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
4ad5717e
Commit
4ad5717e
authored
Jan 16, 2020
by
Raul Puri
Browse files
Merge branch 'model_parallel_generation' into 'master'
force output gathering See merge request ADLR/megatron-lm!17
parents
2d76d065
7a6d630e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
0 deletions
+8
-0
generate_samples.py
generate_samples.py
+8
-0
No files found.
generate_samples.py
View file @
4ad5717e
...
...
@@ -362,6 +362,12 @@ def switch(val1, val2, boolean):
return
(
1
-
boolean
)
*
val1
+
boolean
*
val2
def
sample_sequence_batch
(
model
,
context_tokens
,
context_lengths
,
attention_mask
,
position_ids
,
tokenizer
,
args
,
maxlen
=
None
,
type_ids
=
None
):
if
isinstance
(
model
,
DDP
):
model
=
model
.
module
if
isinstance
(
model
,
FP16_Module
):
model
=
model
.
module
original_output_parallel
=
model
.
parallel_output
model
.
parallel_output
=
False
model
.
eval
()
with
torch
.
no_grad
():
context_length
=
context_lengths
.
min
().
item
()
...
...
@@ -404,6 +410,7 @@ def sample_sequence_batch(model, context_tokens, context_lengths, attention_mask
if
args
.
greedy
:
prev
=
torch
.
argmax
(
logits
,
dim
=-
1
).
view
(
-
1
)
else
:
logits
=
logits
.
float
()
logits
/=
args
.
temperature
logits
=
top_k_logits
(
logits
,
top_k
=
args
.
top_k
,
top_p
=
args
.
top_p
)
log_probs
=
F
.
softmax
(
logits
,
dim
=-
1
)
...
...
@@ -427,6 +434,7 @@ def sample_sequence_batch(model, context_tokens, context_lengths, attention_mask
yield
tokens
,
lengths
if
done
:
break
model
.
parallel_output
=
original_output_parallel
def
prepare_tokenizer
(
args
):
...
...
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