-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible gpt-2-gen bug: assertion error in inference.py #10
Comments
humm - interesting! :o) a bit of debug output could be enlightening here - could you apply this patch and run again?
output should look similar to this:
|
Hi, and thanks a lot for the quick reply. Please see my output below
➜ transformer-lm git:(master) ✗ gpt-2-gen tests/shakespeare-test-run
"Artificial intelligence"
loading model from tests/shakespeare-test-run
generating text for prefix Artificial intelligence
self.model.hparams.n_ctx: 48, tokens_to_generate: 42
Token # 0: <endofline>
Token # 1: ,
Token # 2: ▁I
Token # 3: ,
Token # 4: '
Token # 5: .
Token # 6: ▁the
Token # 7: ,
Token # 8: <endofline>
Token # 9: ,
Token # 10: ▁and
Token # 11: .
Token # 12: <endofline>
Token # 13: <endofline>
Token # 14: .
Token # 15: <endofline>
Token # 16: ,
Token # 17: ▁the
Token # 18: ▁the
Token # 19: <endofline>
Token # 20: ▁the
Token # 21: '
Token # 22: '
Token # 23: '
Token # 24: ,
Token # 25: <endofline>
Token # 26: .
Token # 27: ▁the
Token # 28: <endofline>
Token # 29: <endofline>
Token # 30: ,
Token # 31: <endofline>
Token # 32: ▁I
Token # 33: ,
Token # 34: <endofline>
Token # 35: ▁and
Token # 36: ▁the
Token # 37: <endofline>
Token # 38: <endofline>
Token # 39: ,
Traceback (most recent call last):
File "/Users/.../anaconda3/bin/gpt-2-gen", line 11, in <module>
load_entry_point('lm', 'console_scripts', 'gpt-2-gen')()
File "/Users/.../transformer-lm/lm/inference.py", line 123, in
fire_gen_main
fire.Fire(only_allow_defined_args(gen_main))
File "/Users/.../anaconda3/lib/python3.7/site-packages/fire/core.py",
line 127, in Fire
component_trace = _Fire(component, args, context, name)
File "/Users/.../anaconda3/lib/python3.7/site-packages/fire/core.py",
line 366, in _Fire
component, remaining_args)
File "/Users/.../anaconda3/lib/python3.7/site-packages/fire/core.py",
line 542, in _CallCallable
result = fn(*varargs, **kwargs)
File "/Users/.../transformer-lm/lm/fire_utils.py", line 30, in
_return_wrapped
return function_to_decorate(*args, **kwargs)
File "/Users/.../transformer-lm/lm/inference.py", line 119, in gen_main
tokens_gen = mw.generate_tokens(tokens, tokens_to_generate, top_k)
File "/Users/.../transformer-lm/lm/inference.py", line 88, in
generate_tokens
ntk = self.get_next_top_k(tokens, top_k)
File "/Users/.../transformer-lm/lm/inference.py", line 74, in
get_next_top_k
next_log_probs = self.get_log_probs(tokens)[-1]
File "/Users/.../transformer-lm/lm/inference.py", line 51, in
get_log_probs
assert len(tokens) <= self.model.hparams.n_ctx # TODO
AssertionError
It does strike me as strange that there is a #TODO at exactly that place ^^
…On Wed, 17 Jul 2019 at 13:26, Guenter Bartsch ***@***.***> wrote:
humm - interesting! :o)
a bit of debug output could be enlightening here - could you apply this
patch and run again?
diff --git a/lm/inference.py b/lm/inference.py
index 8768cb7..5a4b78b 100644
--- a/lm/inference.py
+++ b/lm/inference.py
@@ -78,6 +78,8 @@ class ModelWrapper:
def generate_tokens(self, tokens_prefix: List[str], tokens_to_generate: int, top_k: int) -> List[str]:
+ print ("self.model.hparams.n_ctx: %d, tokens_to_generate: %d" % (self.model.hparams.n_ctx, tokens_to_generate))
+
tokens = list(tokens_prefix)
for i in range(tokens_to_generate):
@@ -92,7 +94,7 @@ class ModelWrapper:
# pick next token randomly according to probs distribution
next_token_n = np.random.choice(top_k, p=probs)
next_token = ntk[next_token_n][1]
- # print (next_token)
+ print ("Token # %d: %s" % (i, next_token))
tokens.append(next_token)
output should look similar to this:
(torch) ***@***.*** transformer-lm]$ gpt-2-gen gpt2-german "Ursula von der Leyen"
loading model from gpt2-german
generating text for prefix Ursula von der Leyen
self.model.hparams.n_ctx: 1024, tokens_to_generate: 42
Token # 0: ▁im
Token # 1: ▁Bundestag
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#10?email_source=notifications&email_token=ADNBAKCPLLZ6KITNGTCQJUTP736VPA5CNFSM4IENZY62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2D4HLQ#issuecomment-512213934>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADNBAKDYED2BKAGGVWNNSNLP736VPANCNFSM4IENZY6Q>
.
--
Vennlig hilsen / Kind regards,
Inga Strümke ([email protected])
|
not sure about the TODO (my best guess would be that a nicer error message could be an improvement there), but the real issue seems to be the model you're using which has a pretty small context length? Try to generate fewer tokens (--tokens-to-generate 38) to see if that works. |
Great, that works:
Artificial intelligence, the I and I, and,.,..,, and and',s the
Yes, very good, Shakespeare.
One last thing: what determines the context length of the model (set during
training, I presume?)?
Thanks a bunch!
…On Wed, 17 Jul 2019 at 13:45, Guenter Bartsch ***@***.***> wrote:
not sure about the TODO (my best guess would be that a nicer error message
could be an improvement there), but the real issue seems to be the model
you're using which has a pretty small context length?
Try to generate fewer tokens (--tokens-to-generate 38) to see if that
works.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#10?email_source=notifications&email_token=ADNBAKDUNCMV4HKPYKDGVQLP74A4TA5CNFSM4IENZY62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2D5QTA#issuecomment-512219212>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADNBAKGCSF4JIJZGFL5ADG3P74A4TANCNFSM4IENZY6Q>
.
--
Vennlig hilsen / Kind regards,
Inga Strümke ([email protected])
|
yes, the context length is a model hyperparameter - see /params.json |
Great, thank you so much for helping me!
|
So does that mean that unless I retrain the model with a higher context length, I cannot generate any output longer than 48 characters? Or is there a way to do that without retraining? |
@ceprun for reference, 48 is number of tokens, not characters, and default values for gpt-2 are much larger than that - 48 is just for the integration test. Still there is some context length, but you can still generate contexts which are larger in length in theory, say context length is 4, so you generate:
I hope idea is clear - you truncate previously generated text on the right when feeding as context. |
I have n-ctx = 1024 still facing the assertion error ` 10 frames in _get_next_top_k(self, tokens, top_k, past) in _get_log_probs(self, tokens, past) /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in call(self, *input, **kwargs) /content/drive/My Drive/Colab Notebooks/transformer-lm/lm/model.py in forward(self, x, past) /usr/local/lib/python3.6/dist-packages/torch/utils/checkpoint.py in checkpoint(function, *args, **kwargs) /usr/local/lib/python3.6/dist-packages/torch/utils/checkpoint.py in forward(ctx, run_function, preserve_rng_state, *args) /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in call(self, *input, **kwargs) /content/drive/My Drive/Colab Notebooks/transformer-lm/lm/model.py in forward(self, x, past) /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in call(self, *input, **kwargs) /content/drive/My Drive/Colab Notebooks/transformer-lm/lm/model.py in forward(self, x, past) AssertionError: |
@hafsabukhary aha this is a different error, assert is not correct indeed, it was fixed recently in 4c18649 - so it should work once you update to recent master. Also check out updated |
Thanks for added the generative functionality! Is there a bug or am I doing it wrong?
See command and output below (test dataset after encoding and training as per README)
➜ transformer-lm git:(master) gpt-2-gen tests/shakespeare-test-run "Artificial intelligence"
loading model from tests/shakespeare-test-run
generating text for prefix Artificial intelligence
Traceback (most recent call last):
File "/Users/.../anaconda3/bin/gpt-2-gen", line 11, in
load_entry_point('lm', 'console_scripts', 'gpt-2-gen')()
File "/Users/.../transformer-lm/lm/inference.py", line 120, in fire_gen_main
fire.Fire(only_allow_defined_args(gen_main))
File "/Users/.../anaconda3/lib/python3.7/site-packages/fire/core.py", line 127, in Fire
component_trace = _Fire(component, args, context, name)
File "/Users/.../anaconda3/lib/python3.7/site-packages/fire/core.py", line 366, in _Fire
component, remaining_args)
File "/Users/.../anaconda3/lib/python3.7/site-packages/fire/core.py", line 542, in _CallCallable
result = fn(*varargs, **kwargs)
File "/Users/.../transformer-lm/lm/fire_utils.py", line 30, in _return_wrapped
return function_to_decorate(*args, **kwargs)
File "/Users/.../transformer-lm/lm/inference.py", line 116, in gen_main
tokens_gen = mw.generate_tokens(tokens, tokens_to_generate, top_k)
File "/Users/.../transformer-lm/lm/inference.py", line 86, in generate_tokens
ntk = self.get_next_top_k(tokens, top_k)
File "/Users/.../transformer-lm/lm/inference.py", line 74, in get_next_top_k
next_log_probs = self.get_log_probs(tokens)[-1]
File "/Users/.../transformer-lm/lm/inference.py", line 51, in get_log_probs
assert len(tokens) <= self.model.hparams.n_ctx # TODO
AssertionError
The text was updated successfully, but these errors were encountered: