Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Megatron-LM
Commits
178d4f9c
Commit
178d4f9c
authored
Dec 08, 2021
by
zihanl
Browse files
add copyright
parent
ee7d5721
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
1 deletion
+71
-1
tasks/knwl_dialo/evaluate.py
tasks/knwl_dialo/evaluate.py
+14
-0
tasks/knwl_dialo/preprocessing.py
tasks/knwl_dialo/preprocessing.py
+14
-0
tasks/knwl_dialo/prompt.py
tasks/knwl_dialo/prompt.py
+29
-1
tasks/knwl_dialo/utils.py
tasks/knwl_dialo/utils.py
+14
-0
No files found.
tasks/knwl_dialo/evaluate.py
View file @
178d4f9c
# coding=utf-8
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Model evaluation"""
"""Model evaluation"""
...
...
tasks/knwl_dialo/preprocessing.py
View file @
178d4f9c
# coding=utf-8
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Preprocessing for Wizard of Wikipedia and Wizard of Internet datasets"""
"""Preprocessing for Wizard of Wikipedia and Wizard of Internet datasets"""
...
...
tasks/knwl_dialo/prompt.py
View file @
178d4f9c
# coding=utf-8
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Prompting the pretrained language model to generate knowledge/response"""
"""Prompting the pretrained language model to generate knowledge/response"""
...
@@ -13,6 +27,7 @@ from megatron.training import get_model
...
@@ -13,6 +27,7 @@ from megatron.training import get_model
from
megatron.checkpointing
import
load_checkpoint
from
megatron.checkpointing
import
load_checkpoint
from
megatron.initialize
import
initialize_megatron
from
megatron.initialize
import
initialize_megatron
from
tasks.knwl_dialo.utils
import
get_token_stream
from
tasks.knwl_dialo.utils
import
get_token_stream
# from megatron.text_generation import generate_and_post_process
def
model_provider
(
pre_process
=
True
,
post_process
=
True
):
def
model_provider
(
pre_process
=
True
,
post_process
=
True
):
...
@@ -137,6 +152,7 @@ def generate_samples_by_prompting_input_from_file(model):
...
@@ -137,6 +152,7 @@ def generate_samples_by_prompting_input_from_file(model):
else
:
else
:
context_tokens
=
tokenizer
.
tokenize
(
"EMPTY TEXT"
)
context_tokens
=
tokenizer
.
tokenize
(
"EMPTY TEXT"
)
# raw_text = "EMPTY TEXT"
if
input_pos
%
100
==
0
:
if
input_pos
%
100
==
0
:
print_rank_0
(
"input_pos: %d"
%
input_pos
)
print_rank_0
(
"input_pos: %d"
%
input_pos
)
...
@@ -145,7 +161,13 @@ def generate_samples_by_prompting_input_from_file(model):
...
@@ -145,7 +161,13 @@ def generate_samples_by_prompting_input_from_file(model):
token_stream
=
get_token_stream
(
model
,
[
context_tokens
])
token_stream
=
get_token_stream
(
model
,
[
context_tokens
])
for
_
,
decode_tokens
in
enumerate
(
token_stream
):
for
_
,
decode_tokens
in
enumerate
(
token_stream
):
pass
pass
# outputs = generate_and_post_process(
# model=model,
# prompts=[raw_text],
# tokens_to_generate=args.out_seq_length,
# top_k_sampling=1)
# prompts_plus_generations = outputs[0]
# write the generated output to the output file
# write the generated output to the output file
if
mpu
.
get_tensor_model_parallel_rank
()
==
0
:
if
mpu
.
get_tensor_model_parallel_rank
()
==
0
:
if
mpu
.
is_pipeline_first_stage
():
if
mpu
.
is_pipeline_first_stage
():
...
@@ -158,6 +180,12 @@ def generate_samples_by_prompting_input_from_file(model):
...
@@ -158,6 +180,12 @@ def generate_samples_by_prompting_input_from_file(model):
generated_output
=
generated_output
.
strip
()
generated_output
=
generated_output
.
strip
()
fname_out
.
write
(
generated_output
)
fname_out
.
write
(
generated_output
)
fname_out
.
write
(
"
\n
"
)
fname_out
.
write
(
"
\n
"
)
# generations = prompts_plus_generations[raw_text_len:]
# generations = generations.split("\n")[0]
# generations = generations.strip()
# fname_out.write(generations)
# fname_out.write("\n")
raw_text
=
None
raw_text
=
None
context_count
+=
1
context_count
+=
1
...
...
tasks/knwl_dialo/utils.py
View file @
178d4f9c
# coding=utf-8
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utils (functions) for both prompting and finetuning"""
"""Utils (functions) for both prompting and finetuning"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment