nemo_automodel.components.models.qwen3_8_flash_next.model
nemo_automodel.components.models.qwen3_8_flash_next.model
Trainable Qwen3.8-Flash-Next conditional-generation model.
This implementation uses the checkpoint’s compressed-block QSA router and
FlexAttention or optional SM90 CuTe sparse GQA for CUDA BF16 long-sequence SFT,
with a PyTorch oracle for CPU and numerical parity. Pipeline parallelism splits
the decoder layers into stages that exchange the flattened HyperConnection state
[batch, sequence, hc_count * hidden]; the final stage owns the HC mixer and
lm_head. Tensor parallelism remains unsupported. Context parallelism uses a
model-owned contiguous sequence shard for QSA, GDN, and PLE, and composes with
sequence packing; it has not been validated together with pipeline parallelism.
Module Contents
Classes
Functions
Data
API
Bases: CausalLMOutputWithPast
Causal-LM output with optional per-layer HC states for parity capture.
Bases: HFCheckpointingMixin, Module, MoEFSDPSyncMixin
Trainable language-only Qwen3.8-Flash-Next causal-LM wrapper.
Convert PLE owner shards to global DTensors before FSDP wrapping.
Under pipeline parallelism this runs per stage on that stage’s mesh, after the stage split, so only the stage that holds the PLE layer binds and shards the table.
Parameters:
Flattened data/context shard mesh of this pipeline stage. A pending table binds its group as the owner group; an explicitly bound table requires the identical rank order.
Returns: set[nn.Parameter]
The exact registered parameter identities that FSDP must ignore
Keep the final HyperConnection mixer on the last pipeline stage.
The generic stage planner only knows embed_tokens, layers,
norm, rotary_emb and lm_head. The HC mixer that collapses the
hc_count streams before lm_head lives next to it.
Parameters:
Planner output, one module FQN list per stage.
FQN prefix of the text decoder, ending in ..
Unused; the mixer location is fixed by this class.
Returns: list[list[str]]
Copied per-stage FQN lists with the mixer appended to the last stage.
Run language-only generation and project final HC-mixed states.
Parameters:
Raw tokenizer IDs of shape [batch, sequence]. On a
non-first pipeline stage, where embed_tokens is absent, the
schedule passes the previous stage’s floating-point HC state
[batch, sequence, hc_count * hidden_size] here instead; it
is routed as inputs_embeds.
Optional token-validity mask of shape
[batch, sequence] or backend-specific attention mask.
Optional positions of shape [batch, sequence] or
[axes, batch, sequence].
Optional embeddings of shape
[batch, sequence, hidden_size].
Optional labels of shape [batch, sequence]. They are
accepted for recipe compatibility; loss is computed externally.
Cache state; unsupported.
Cache request; True is unsupported.
0 for all positions, a positive trailing count,
or an integer tensor of shape [kept_sequence] containing
explicit sequence indices.
Explicit True returns the embedding,
every per-layer HC state, and the final state. When omitted,
config.output_hidden_states=True returns only the final
state for fused linear cross entropy without retaining every
decoder activation.
Internal contiguous CP metadata with replicated
raw-ID/padding tensors of shape [batch, global_sequence].
Text-attention backend metadata.
Returns: Qwen3_8_FlashNextCausalLMOutput
Causal-LM output with logits [batch, kept_sequence, vocab_size].
Construct from a parsed Qwen3.8-Flash-Next configuration.
Construct architecture from a local/HF config before checkpoint load.
Return the text token embedding module.
Return the untied LM projection.
Return static input/output meta tensors for this pipeline stage.
Stages exchange the flattened HC state, so a non-first stage receives
[batch, sequence, hc_count * hidden] rather than [batch, sequence, hidden]. The last stage collapses it through the HC mixer and emits
logits.
Parameters:
Whether this stage holds embed_tokens.
Pipeline micro-batch size.
Sequence length of the padded batch.
Activation dtype of the exchanged tensors.
Returns: tuple[torch.Tensor, ...]
(inputs_meta, outputs_meta) tuples of meta tensors. The first-stage
Initialize checkpoint-free model weights.
Parameters:
Target device for backend initializers.
Final model parameter dtype, excluding intrinsic fp32 GDN state.
Return Qwen3.8-Flash-Next’s contiguous model-owned CP batch sharder.
Parameters:
Full-sequence batch. Token-aligned tensors have shape
[batch, global_sequence, ...] and remain unchanged until
the returned sharder is invoked.
Accepted for the framework hook contract; Qwen3.8-Flash-Next shards each non-packed batch directly and does not use it.
Returns: dict[str, Any]
Mapping containing one unresolved cp_sharder. Once invoked it
Replace the text token embedding module.
Replace the untied LM projection.
Bases: Module
Language-only Qwen3.8-Flash-Next decoder wrapper.
Run the language-only Qwen3.8-Flash-Next decoder.
Parameters:
Raw IDs of shape [batch, sequence]; required on the
stage that holds the PLE layer.
Optional token-validity mask of shape
[batch, sequence] or backend-specific attention mask.
Optional positions of shape [batch, sequence] or
[axes, batch, sequence].
Optional embeddings of shape
[batch, sequence, hidden_size], or the incoming HC state
[batch, sequence, hc_count * hidden_size] on a non-first
pipeline stage.
Cache state; unsupported for training.
Capture decoder HC states.
Internal contiguous CP metadata with replicated
raw-ID/padding tensors of shape [batch, global_sequence].
Text-attention backend arguments.
Returns: BaseModelOutputWithPast
Base-model output whose final text states have shape
Bases: Module
Qwen3.8-Flash-Next text decoder with four HC streams and one PLE layer.
Tensor layout
Token embeddings start as [batch, sequence, hidden_size]. Decoder
layers retain flattened HC state
[batch, sequence, hc_count * hidden_size]. The final learned HC read
collapses it back to [batch, sequence, hidden_size].
Parameters:
Text architecture configuration.
Native attention, linear, and MoE backend configuration.
Optional native MoE configuration override.
Optional fields merged into the default MoE config.
Explicit group that owns contiguous PLE table
row shards. When omitted in a distributed run the table binds the
FSDP (data/context shard) mesh of the pipeline stage that holds it
during parallelization, so the owner group is the stage’s EP/FSDP
group rather than the world. Only the MoE parallelizer binds it,
so PLE layers require ep_size > 1.
Optional tiny-table override for unit tests. The
released checkpoint uses [320001536, 160] globally.
Run the HC decoder and final HC mixer.
Parameters:
Raw tokenizer IDs of shape [batch, sequence]. They
remain required when inputs_embeds is supplied and this
stage holds the PLE layer, because PLE hashes the raw IDs.
Optional precomputed token/vision embeddings of shape
[batch, sequence, hidden_size], or on a non-first pipeline
stage the incoming flattened HC state of shape
[batch, sequence, hc_count * hidden_size].
Optional mask of shape [batch, sequence] or a
backend-specific attention mask.
Optional positions of shape [batch, sequence] or
[axes, batch, sequence].
Optional mask [batch, sequence] where True is padding.
KV/SSM cache; unsupported by this training backend.
Cache request; True is unsupported.
Include embedding, per-layer HC, and final collapsed states for parity diagnostics.
Internal contiguous CP metadata. Its replicated
raw-ID and padding tensors have shape [batch, global_sequence]; model activations remain local
[batch, sequence, hidden] tensors.
Attention backend metadata.
Returns: BaseModelOutputWithPast
A base-model output whose last_hidden_state has shape
Return the raw-token embedding table.
Initialize decoder weights for training from scratch.
Parameters:
Device used by layer initializers.
Replace the raw-token embedding table.
Parameters:
Module mapping [batch, sequence] IDs to
[batch, sequence, hidden_size] embeddings.
Return a typed backend with the model’s unfused rotary path.