Repository navigation
fix(generation): Enforce the auto-compile cache check for encoder-decoder models #48364
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
Changes from 2 commits
274afcf
0cff6c1
5a3c5ba
6628339
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5114,6 +5114,23 @@ def test_cpu_offload_doesnt_compile(self): | |
| _ = model_cpu.generate(input_ids, **generate_kwargs) | ||
| self.assertFalse(hasattr(model_cpu, "_compiled_call")) | ||
|
|
||
| def test_compileable_default_cache_doesnt_compile_encoder_decoder(self): | ||
| """Test that a compileable default cache doesn't trigger compilation on encoder-decoder models either""" | ||
| model = AutoModelForSeq2SeqLM.from_pretrained("hf-internal-testing/tiny-random-bart") | ||
| decoder_config = copy.deepcopy(model.config.get_text_config(decoder=True)) | ||
| # Linear attention layers are statically shaped, so the default `DynamicCache` is compileable (e.g. Mamba) | ||
| decoder_config.layer_types = ["linear_attention"] * decoder_config.num_hidden_layers | ||
| self_attention_cache = DynamicCache(config=decoder_config) | ||
| self.assertTrue(self_attention_cache.is_compileable) | ||
|
|
||
| cache = EncoderDecoderCache( | ||
| self_attention_cache, DynamicCache(config=model.config.get_text_config(decoder=True)) | ||
| ) | ||
| generation_config = GenerationConfig() | ||
| generation_config.compile_config = CompileConfig() | ||
| generation_config.compile_config._compile_all_devices = True | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering, could we set it at construction time?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't unfortunately, it's a normal attr not a dataclass field in CompileConfig. Set it like the other usages. |
||
| self.assertFalse(model._valid_auto_compile_criteria({"past_key_values": cache}, generation_config)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it needs the static cache to be true?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup because otherwise the test passes on CPU regardless. Static cache alone doesn't repro the issue either (both |
||
|
|
||
| def test_custom_generate_from_argument_in_generate(self): | ||
| """Tests that the `custom_generate` argument is used when passed to `generate`""" | ||
| model = AutoModelForCausalLM.from_pretrained( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be overkill since it only lives for this test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, dropped it :)