Repository navigation
🚨 Generation cache preparation #43679
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
Merged
zucchini-nlp
merged 11 commits into
huggingface:main
from
zucchini-nlp:cache-prefill-chunk
Feb 4, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dfad28c
do smth
zucchini-nlp b241557
how did this even happen O_o
zucchini-nlp bd31bb2
fix models
zucchini-nlp c042373
dia needs only one prefill, fix
zucchini-nlp d58e5b7
fxi repo again
zucchini-nlp 524734f
comments, comments
zucchini-nlp 4493bb2
almost forgot
zucchini-nlp e10455e
explicit keyword arg
zucchini-nlp 57f2463
Merge branch 'main' into cache-prefill-chunk
zucchini-nlp 0614fd0
Merge branch 'main' into cache-prefill-chunk
zucchini-nlp db40d72
Merge branch 'main' into cache-prefill-chunk
zucchini-nlp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -930,7 +930,7 @@ def forward( | |
| inputs_embeds = self.embed_tokens(input_ids) | ||
|
|
||
| if use_cache and past_key_values is None: | ||
| past_key_values = DynamicCache() | ||
| past_key_values = DynamicCache(config=self.config) | ||
|
|
||
| if cache_position is None: | ||
| past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0 | ||
|
|
@@ -1229,8 +1229,15 @@ def forward( | |
| if (input_ids is None) ^ (inputs_embeds is not None): | ||
| raise ValueError("You must specify exactly one of input_ids or inputs_embeds") | ||
|
|
||
| if use_cache and past_key_values is None: | ||
| past_key_values = EncoderDecoderCache(DynamicCache(config=self.config), DynamicCache(config=self.config)) | ||
| if use_cache: | ||
| if past_key_values is None: | ||
| past_key_values = EncoderDecoderCache( | ||
| DynamicCache(config=self.config), DynamicCache(config=self.config) | ||
| ) | ||
| elif not isinstance(past_key_values, EncoderDecoderCache): | ||
| # BLT uses an encoder-decoder cache even though it is not en encoder-decoder model. Create a cross-cache | ||
| # if not yet created by the user | ||
| past_key_values = EncoderDecoderCache(past_key_values, DynamicCache(config=self.config)) | ||
|
zucchini-nlp marked this conversation as resolved.
Resolved
|
||
|
|
||
| # Extract input embeddings as early as possible | ||
| if inputs_embeds is not None: | ||
|
|
@@ -1377,7 +1384,7 @@ class BltForCausalLM(BltPreTrainedModel, GenerationMixin): | |
| _tied_weights_keys = {"model.local_encoder.embed_tokens.weight": "lm_head.weight"} | ||
|
|
||
| def __init__(self, config: BltConfig): | ||
| super().__init__(config.get_text_config()) | ||
| super().__init__(config) | ||
| self.text_config = config.get_text_config() | ||
|
Comment on lines
-1380
to
1388
Member
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. not a good practice if |
||
| self.vocab_size = config.vocab_size | ||
| self.model = BltModel(config) | ||
|
|
@@ -1433,8 +1440,8 @@ def forward( | |
| ```python | ||
| >>> from transformers import AutoTokenizer, BltForCausalLM | ||
|
|
||
| >>> model = BltForCausalLM.from_pretrained("Llama-3.2-11B-Vision") | ||
| >>> tokenizer = AutoTokenizer.from_pretrained("Llama-3.2-11B-Vision") | ||
| >>> model = BltForCausalLM.from_pretrained("itazap/blt-1b-hf") | ||
| >>> tokenizer = AutoTokenizer.from_pretrained("itazap/blt-1b-hf") | ||
|
|
||
| >>> prompt = "If I had to write a haiku, it would be:" | ||
| >>> inputs = tokenizer(prompt, return_tensors="pt") | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
just a naming change, imo this is more descriptive