-
Notifications
You must be signed in to change notification settings - Fork 804
Fix intermediates for Gemma example #5409
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
copybara-service
merged 2 commits into
main
from
gemma-example-using-grain--fix-intermediates
Apr 23, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| # Copyright 2024 The Flax Authors. | ||
| # | ||
| # 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. | ||
|
|
||
| """Default Hyperparameter configuration.""" | ||
|
|
||
| import dataclasses | ||
|
|
||
| from train import TrainConfig | ||
|
|
||
|
|
||
| @dataclasses.dataclass(unsafe_hash=True) | ||
| class Config: | ||
| # Path to load or store sentencepiece vocab file. | ||
| vocab_path: str | None = None | ||
| # Vocabulary size if `vocab_path` is not given. | ||
| vocab_size: int = 35_008 # lm1b dataset vocab size: 35913 (Gemma expected vocab size: 262_144) | ||
| # Maximum number of characters to use for training. | ||
| max_corpus_chars: int = 10**7 | ||
| # Name of TFDS translation dataset to use. | ||
| dataset_name: str = 'lm1b' | ||
| # Optional name of TFDS translation dataset to use for evaluation. | ||
| eval_dataset_name: str = 'lm1b' | ||
| # Optional name of TFDS split to use for evaluation. | ||
| eval_split: str = 'test' | ||
| # Per device batch size for training. | ||
| per_device_batch_size: int = 16 | ||
| # Per device batch size for training. | ||
| eval_per_device_batch_size: int = 16 | ||
| # Grain prefetch number of workers. | ||
| prefetch_num_workers: int | None = None | ||
|
|
||
| # Prompt for language model sampling | ||
| prompts: tuple[str, ...] = ( | ||
| 'Paris is a the capital', | ||
| 'Flax is a', | ||
| # From train set: | ||
| 'The shutdown was aimed at creating efficiencies as', | ||
| # -> the plant was already operating at its maximum capacity of 3,000 tonnes of cellulose paste per day | ||
| 'A big theme of this hire is that there are parts of', | ||
| # -> our operations that to use a pretty trite phrase , need to be taken to the next level ... | ||
|
|
||
| # From test set: | ||
| 'Because of Bear Stearns , many analysts are', | ||
| # -> raising the odds that a 2008 recession could be worse than expected | ||
| 'Next month , the Brazilian bourse', | ||
| # -> opens a London office', | ||
| ) | ||
| # Temperature for top_p sampling. | ||
| sampling_temperature: float = 0.0 | ||
| # Top-p sampling threshold. | ||
| sampling_top_p: float = 0.95 | ||
|
|
||
| # Number of steps to take during training. | ||
| num_train_steps: int = 100_000 | ||
| # Number of steps to take during evaluation. | ||
| # Large enough to evaluate all samples: 306_688 / (32 * 8) = 1198 | ||
| # num_eval_steps: int = 2_000 | ||
| num_eval_steps: int = 500 | ||
| # Number of steps to generate predictions. | ||
| # -1 will use the whole eval dataset. | ||
| num_predict_steps: int = 50 | ||
| # Base learning rate. | ||
| learning_rate: float = 0.0016 | ||
| # Linear learning rate warmup. | ||
| warmup_steps: int = 1000 | ||
| # Cross entropy loss label smoothing. | ||
| label_smoothing: float = 0.0 | ||
| # Decay factor for AdamW style weight decay. | ||
| weight_decay: float = 0.1 | ||
| # Maximum length cutoff for training examples. | ||
| max_target_length: int = 1024 | ||
| # Maximum length cutoff for eval examples. | ||
| max_eval_target_length: int = 1024 | ||
|
|
||
| # Gemma transformer name. | ||
| # Possible values defined in transformer.TransformerConfig: | ||
| # (gemma_2b, gemma_7b, gemma2_2b, gemma2_9b, gemma2_27b, gemma3_270m, gemma3_1b, gemma3_4b, ...) | ||
| transformer_name: str | None = "gemma3_270m" | ||
| # or alternatively define the model using the dict of parameters | ||
| transformer_params: dict | None = None | ||
|
|
||
| # Whether to save model checkpoints. | ||
| save_checkpoints: bool = True | ||
| # Whether to restore from existing model checkpoints. | ||
| restore_checkpoints: bool = True | ||
| # Save a checkpoint every these number of steps. | ||
| checkpoint_every_steps: int = 10_000 | ||
| # Frequency of eval during training, e.g. every 2_000 steps. | ||
| eval_every_steps: int = 2_000 | ||
| # Use bfloat16 mixed precision training instead of float32. | ||
| use_bfloat16: bool = True | ||
| # Integer for PRNG random seed. | ||
| seed: int = 0 | ||
|
|
||
| # Parallelism | ||
| mesh_axes: tuple[str, ...] = ('fsdp', 'tensor') | ||
| data_sharding: tuple[str, ...] = ('fsdp', ) | ||
|
|
||
| fsdp_parallelism: int = -1 | ||
| tensor_parallelism: int = 1 | ||
|
|
||
| sow_config: dict = dataclasses.field( | ||
| default_factory=lambda: { | ||
| "rs_after_attention": True, | ||
| "rs_after_ffw": True, | ||
| "attn_logits_topk": 5, | ||
| "mlp_hidden_topk": 5, | ||
| } | ||
| ) | ||
|
|
||
| def replace(self, **kwargs): | ||
| return dataclasses.replace(self, **kwargs) | ||
|
|
||
|
|
||
| def get_config() -> TrainConfig: | ||
| """Get the default hyperparameter configuration.""" | ||
| config = Config() | ||
| return TrainConfig(**dataclasses.asdict(config)) |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.