bridge.recipes.gemma.gemma3#
Module Contents#
Classes#
Typed options accepted by Gemma3 family recipe helpers. |
|
Typed options accepted by Gemma3 finetuning recipe helper functions. |
Functions#
Return a pre-training config for Gemma3 1B. |
|
Create a pre-training configuration for Gemma3 family models. |
|
Return a finetuning config for Gemma3 1B. |
|
Create a finetuning configuration for Gemma3 models. |
Data#
API#
- class bridge.recipes.gemma.gemma3.Gemma3CommonKwargs#
Bases:
typing_extensions.TypedDictTyped options accepted by Gemma3 family recipe helpers.
Initialization
Initialize self. See help(type(self)) for accurate signature.
- provider_class: type#
None
- hf_path: str | None#
None
- dir: str | None#
None
- name: str#
None
- data_paths: list[str] | None#
None
- data_args_path: str | None#
None
- train_data_path: list[str] | None#
None
- valid_data_path: list[str] | None#
None
- test_data_path: list[str] | None#
None
- per_split_data_args_path: str | None#
None
- mock: bool#
None
- tensor_model_parallel_size: int#
None
- pipeline_model_parallel_size: int#
None
- pipeline_dtype: torch.dtype | None#
None
- virtual_pipeline_model_parallel_size: int | None#
None
- context_parallel_size: int#
None
- sequence_parallel: bool#
None
- use_megatron_fsdp: bool#
None
- account_for_embedding_in_pipeline_split: bool#
None
- account_for_loss_in_pipeline_split: bool#
None
- train_iters: int#
None
- global_batch_size: int#
None
- micro_batch_size: int#
None
- seq_length: int#
None
- lr: float#
None
- min_lr: float#
None
- lr_warmup_iters: int#
None
- lr_decay_iters: int | None#
None
- eval_interval: int#
None
- save_interval: int#
None
- use_null_tokenizer: bool#
None
- precision_config: megatron.bridge.training.mixed_precision.MixedPrecisionConfig | str | None#
None
- comm_overlap_config: megatron.bridge.training.comm_overlap.CommOverlapConfig | None#
None
- class bridge.recipes.gemma.gemma3.Gemma3FinetuneKwargs#
Bases:
typing_extensions.TypedDictTyped options accepted by Gemma3 finetuning recipe helper functions.
This is separate from Gemma3CommonKwargs to avoid confusion - finetuning uses SQuAD dataset by default, not the data path fields.
Initialization
Initialize self. See help(type(self)) for accurate signature.
- dir: str | None#
None
- name: str#
None
- pretrained_checkpoint: str | None#
None
- peft: str | megatron.bridge.peft.base.PEFT | None#
None
- packed_sequence: bool#
None
- train_iters: int#
None
- global_batch_size: int | None#
None
- micro_batch_size: int#
None
- seq_length: int | None#
None
- eval_interval: int#
None
- save_interval: int#
None
- finetune_lr: float | None#
None
- min_lr: float#
None
- lr_warmup_iters: int#
None
- lr_decay_iters: int | None#
None
- wandb_project: str | None#
None
- wandb_entity: str | None#
None
- wandb_exp_name: str | None#
None
- precision_config: megatron.bridge.training.mixed_precision.MixedPrecisionConfig | str | None#
None
- bridge.recipes.gemma.gemma3.SEQUENCE_LENGTH_32K: int#
32768
- bridge.recipes.gemma.gemma3.SEQUENCE_LENGTH_128K: int#
131072
- bridge.recipes.gemma.gemma3.gemma3_1b_pretrain_config(
- **user_kwargs: typing_extensions.Unpack[bridge.recipes.gemma.gemma3.Gemma3CommonKwargs],
Return a pre-training config for Gemma3 1B.
See
_gemma3_commonfor the full list of parameters.
- bridge.recipes.gemma.gemma3._gemma3_common(
- provider_class: type,
- hf_path: str | None = None,
- dir: str | None = None,
- name: str = 'default',
- data_paths: list[str] | None = None,
- data_args_path: str | None = None,
- train_data_path: list[str] | None = None,
- valid_data_path: list[str] | None = None,
- test_data_path: list[str] | None = None,
- per_split_data_args_path: str | None = None,
- mock: bool = False,
- tensor_model_parallel_size: int = 1,
- pipeline_model_parallel_size: int = 1,
- pipeline_dtype: torch.dtype | None = None,
- virtual_pipeline_model_parallel_size: int | None = None,
- context_parallel_size: int = 1,
- sequence_parallel: bool = False,
- use_megatron_fsdp: bool = False,
- account_for_embedding_in_pipeline_split: bool = False,
- account_for_loss_in_pipeline_split: bool = False,
- train_iters: int = 1168251,
- global_batch_size: int = 512,
- micro_batch_size: int = 1,
- seq_length: int = 131072,
- lr: float = 0.0003,
- min_lr: float = 3e-05,
- lr_warmup_iters: int = 2000,
- lr_decay_iters: int | None = None,
- eval_interval: int = 2000,
- save_interval: int = 500,
- use_null_tokenizer: bool = True,
- precision_config: megatron.bridge.training.mixed_precision.MixedPrecisionConfig | str | None = 'bf16_mixed',
- comm_overlap_config: megatron.bridge.training.comm_overlap.CommOverlapConfig | None = None,
Create a pre-training configuration for Gemma3 family models.
- Parameters:
provider_class (type) β Gemma3 model provider class (e.g., Gemma3ModelProvider1B).
hf_path (str | None) β HuggingFace model path (e.g., βgoogle/gemma-3-1b-ptβ).
dir (str | None) β Base directory for saving logs and checkpoints.
name (str) β Name of the pre-training run.
data_paths (list[str] | None) β List of paths to dataset files. If None, mock data will be used.
data_args_path (str | None) β Path to file containing data arguments.
train_data_path (list[str] | None) β List of training data paths.
valid_data_path (list[str] | None) β List of validation data paths.
test_data_path (list[str] | None) β List of test data paths.
per_split_data_args_path (str | None) β Path to JSON file with per-split data configuration.
mock (bool) β Whether to use mock data. If True, ignores data_paths.
tensor_model_parallel_size (int) β Degree of tensor model parallelism.
pipeline_model_parallel_size (int) β Degree of pipeline model parallelism.
pipeline_dtype (torch.dtype | None) β Data type for pipeline parallelism.
virtual_pipeline_model_parallel_size (int | None) β Size of virtual pipeline parallelism.
context_parallel_size (int) β Degree of context parallelism.
sequence_parallel (bool) β Whether to use sequence parallelism.
use_megatron_fsdp (bool) β Whether to use Megatron FSDP.
account_for_embedding_in_pipeline_split (bool) β Whether to account for embedding in pipeline split.
account_for_loss_in_pipeline_split (bool) β Whether to account for loss in pipeline split.
train_iters (int) β Total number of training iterations.
global_batch_size (int) β Global batch size for training.
micro_batch_size (int) β Micro batch size for training.
seq_length (int) β Sequence length for training data.
lr (float) β Learning rate.
min_lr (float) β Minimum learning rate for cosine decay.
lr_warmup_iters (int) β Number of warmup iterations for the learning rate.
lr_decay_iters (int | None) β Number of iterations over which to decay the LR.
eval_interval (int) β Evaluation interval.
save_interval (int) β Checkpoint save interval.
use_null_tokenizer (bool) β Whether to use null tokenizer for synthetic data.
precision_config (MixedPrecisionConfig | str | None) β Precision configuration for the model.
comm_overlap_config (CommOverlapConfig | None) β Communication overlap configuration.
- Returns:
Configuration for pre-training.
- Return type:
- bridge.recipes.gemma.gemma3.gemma3_1b_finetune_config(
- **user_kwargs: typing_extensions.Unpack[bridge.recipes.gemma.gemma3.Gemma3FinetuneKwargs],
Return a finetuning config for Gemma3 1B.
Default configuration: 1 node, 8 GPUs, LoRA
LoRA (default): TP=1, PP=1, LR=1e-4, dim=8, alpha=16
DoRA: TP=1, PP=1, LR=1e-4, dim=8, alpha=16
Full SFT (peft=None): TP=1, PP=1, LR=5e-6
Matches NeMo2 recipe at nemo/collections/llm/recipes/gemma3_1b.py
- bridge.recipes.gemma.gemma3._gemma3_finetune_common(
- hf_path: str,
- dir: str | None = None,
- name: str = 'default',
- pretrained_checkpoint: str | None = None,
- packed_sequence: bool = False,
- train_iters: int = 100,
- global_batch_size: int | None = None,
- micro_batch_size: int = 1,
- seq_length: int | None = None,
- eval_interval: int = 50,
- save_interval: int = 100,
- finetune_lr: float | None = None,
- min_lr: float = 0.0,
- lr_warmup_iters: int = 10,
- lr_decay_iters: int | None = None,
- wandb_project: str | None = None,
- wandb_entity: str | None = None,
- wandb_exp_name: str | None = None,
- precision_config: megatron.bridge.training.mixed_precision.MixedPrecisionConfig | str | None = None,
Create a finetuning configuration for Gemma3 models.
- Parameters:
hf_path (str) β HuggingFace model path (e.g., βgoogle/gemma-3-1b-ptβ).
dir (str | None) β Base directory for saving logs and checkpoints.
name (str) β Name of the finetuning run.
pretrained_checkpoint (str | None) β Path to pretrained checkpoint to load.
packed_sequence (bool) β Whether to use packed sequences for training efficiency.
train_iters (int) β Total number of training iterations.
global_batch_size (int | None) β Global batch size for training.
micro_batch_size (int) β Micro batch size for training.
seq_length (int | None) β Sequence length for training data.
eval_interval (int) β Evaluation interval.
save_interval (int) β Checkpoint save interval.
finetune_lr (float | None) β Learning rate for finetuning.
min_lr (float) β Minimum learning rate for cosine decay.
lr_warmup_iters (int) β Number of warmup iterations for the learning rate.
lr_decay_iters (int | None) β Number of iterations over which to decay the LR.
wandb_project (str | None) β Weights & Biases project name.
wandb_entity (str | None) β Weights & Biases entity name.
wandb_exp_name (str | None) β Weights & Biases experiment name.
precision_config (MixedPrecisionConfig | str | None) β Precision configuration for the model.
- Returns:
Configuration for finetuning.
- Return type: