nemo_automodel.components.models.bagel
nemo_automodel.components.models.bagel
BAGEL mixed-modal LLM (Qwen2 + SigLIP-NaViT + MoT shell).
Submodules
nemo_automodel.components.models.bagel.attention_masksnemo_automodel.components.models.bagel.autoencodernemo_automodel.components.models.bagel.configurationnemo_automodel.components.models.bagel.connectornemo_automodel.components.models.bagel.embeddingsnemo_automodel.components.models.bagel.hf_backbone_loadernemo_automodel.components.models.bagel.modelnemo_automodel.components.models.bagel.modeling_qwen2_packednemo_automodel.components.models.bagel.modeling_siglip_navitnemo_automodel.components.models.bagel.parallelizationnemo_automodel.components.models.bagel.state_dict_adapter
Package Contents
Classes
Functions
API
Bases: Module
BAGEL Stage 2 autoencoder wrapper.
Decode scaled latents to image tensors.
Encode image tensors to scaled latents.
Encode and decode image tensors.
Architecture parameters for the BAGEL/FLUX autoencoder.
Bases: PretrainedConfig
Top-level BAGEL config.
The text and vision sub-configs are nested PretrainedConfig
instances (not bare dicts) so callers can introspect them the same way
they would with any other HF config.
Attribute aliases:
text_config<->llm_config(both point at the same object)vision_config<->vit_config(ditto)
Bases: HFCheckpointingMixin, Module
BAGEL mixed-modal LLM wrapper for understanding and optional generation.
visual_gen=False gives the Stage 1 understanding-only path. Stage 2
sets visual_gen=True and uses the MoT *_moe_gen parameter siblings,
VAE latents prepared by the recipe, and the flow-matching MSE head.
Run the BAGEL mixed-modal forward.
Stage 1 (visual_gen=False) skips the flow-matching branch and MSE
computation; Stage 2 activates both. ce_loss_weights is accepted
for data-pipeline compatibility but not consumed here - CE is returned
per-token (reduction="none") and the trainer may apply weights
downstream.
Stage 2 inputs (padded_latent, patchified_vae_latent_shapes,
packed_latent_position_ids, packed_vae_token_indexes,
packed_timesteps, mse_loss_indexes) are produced by the
BAGEL collator when a pack contains t2i/edit samples. padded_latent
is the VAE-encoded latent tensor; recipe must call vae_model.encode
on the raw padded_images before forward; this module does not own
the VAE.
Returns: Dict[str, torch.Tensor | None]
dict(ce=Tensor|None, mse=Tensor|None) - both can be None
Load a BAGEL-7B-MoT checkpoint directory into this class.
Reads config.json via BagelConfig.from_pretrained, constructs
an empty model, and then loads ema.safetensors filtered by
BagelStateDictAdapter. Stage 2 VAE weights are loaded by the
recipe because the VAE is not owned by this module tree.
Parameters:
Directory containing the HF-layout BAGEL checkpoint.
1 (UND only) or 2 (UND + GEN). Strings
"stage1" / "stage2" are also accepted.
If True, raise on state-dict keys that don’t match the
adapter patterns. Defaults to False for compatibility with
checkpoint sidecar files.
Model overrides. backend is passed to the BAGEL model
constructor; the remaining values are forwarded to
BagelConfig.from_pretrained.
Returns: 'BagelForUnifiedMultimodal'
A fully-initialized BagelForUnifiedMultimodal with weights
Initialize BAGEL weights after AM materializes a from_config model.
BagelForUnifiedMultimodal is an nn.Module root, not a HF
PreTrainedModel root. AM’s meta-device from_config path
materializes parameters after sharding and then calls this method.
Delegate Qwen/SigLIP subtrees to their HF-style initializers, then
initialize BAGEL-only connector and generation modules.
Return True if this custom class supports config.
Load the BAGEL autoencoder from ae.safetensors.
Parameters:
Local path to ae.safetensors. If None, the module is
returned with randomly initialized weights.
Returns: tuple[AutoEncoder, AutoEncoderParams]
The autoencoder module and its architecture parameters.