nemo_automodel.components.models.hy_v3.model

View as Markdown

HYV3ForCausalLM — Tencent Hy3-preview (295B MoE) SFT support.

Architecture (from tencent/Hy3-preview config.json):

  • 80 transformer layers; layer 0 is dense, layers 1-79 are MoE
  • MoE: 192 routed experts + 1 shared expert, top-8 activated
  • Sigmoid routing with expert-bias correction (e_score_correction_bias)
  • GQA: 64 Q heads, 8 KV heads, head_dim=128
  • Per-head QK RMSNorm before RoPE
  • 256K context, rope_theta=11158840

Module Contents

Classes

Data

ModelClass

API

class nemo_automodel.components.models.hy_v3.model.Block(
layer_idx: int,
config: typing.Any,
moe_config: nemo_automodel.components.moe.config.MoEConfig,
backend: nemo_automodel.components.models.common.BackendConfig
)

Bases: Module

input_layernorm
mlp
post_attention_layernorm
self_attn
= HYV3Attention(config, backend)
nemo_automodel.components.models.hy_v3.model.Block._mlp(
x: torch.Tensor,
padding_mask: torch.Tensor | None
) -> torch.Tensor
nemo_automodel.components.models.hy_v3.model.Block.forward(
x: torch.Tensor,
freqs_cis: torch.Tensor,
attention_mask: torch.Tensor | None = None,
padding_mask: torch.Tensor | None = None,
attn_kwargs: typing.Any = {}
) -> torch.Tensor
nemo_automodel.components.models.hy_v3.model.Block.init_weights(
buffer_device: torch.device
)
class nemo_automodel.components.models.hy_v3.model.HYV3ForCausalLM(
config: typing.Any,
moe_config: nemo_automodel.components.moe.config.MoEConfig | None = None,
backend: nemo_automodel.components.models.common.BackendConfig | None = None,
kwargs = {}
)

Bases: HFCheckpointingMixin, Module, MoEFSDPSyncMixin

backend
= backend or BackendConfig()
lm_head
model
state_dict_adapter
nemo_automodel.components.models.hy_v3.model.HYV3ForCausalLM.forward(
input_ids: torch.Tensor,
position_ids: torch.Tensor | None = None,
attention_mask: torch.Tensor | None = None,
padding_mask: torch.Tensor | None = None,
logits_to_keep: typing.Union[int, torch.Tensor] = 0,
output_hidden_states: typing.Optional[bool] = None,
attn_kwargs: typing.Any = {}
) -> transformers.modeling_outputs.CausalLMOutputWithPast

Forward pass returning :class:~transformers.modeling_outputs.CausalLMOutputWithPast.

Parameters:

input_ids
torch.Tensor

Input token IDs. BSHD: [B, S]; THD: [1, T] (squeezed internally).

position_ids
torch.Tensor | NoneDefaults to None

Optional position indices.

attention_mask
torch.Tensor | NoneDefaults to None

Optional 2D padding mask [B, S].

padding_mask
torch.Tensor | NoneDefaults to None

Optional padding mask used by the THD squeeze helper.

logits_to_keep
Union[int, torch.Tensor]Defaults to 0

If 0 (default) compute logits for all positions; otherwise only compute logits for the last logits_to_keep token positions (avoids materialising the full logit matrix during generation).

output_hidden_states
Optional[bool]Defaults to None

Whether to carry the final hidden states on the output.

**attn_kwargs
AnyDefaults to {}

Additional arguments forwarded to the base model (e.g. qkv_format, cu_seqlens, CP kwargs).

Returns: CausalLMOutputWithPast

class:~transformers.modeling_outputs.CausalLMOutputWithPast with logits

nemo_automodel.components.models.hy_v3.model.HYV3ForCausalLM.from_config(
config: typing.Any,
moe_config: nemo_automodel.components.moe.config.MoEConfig | None = None,
backend: nemo_automodel.components.models.common.BackendConfig | None = None,
kwargs = {}
)
classmethod
nemo_automodel.components.models.hy_v3.model.HYV3ForCausalLM.from_pretrained(
pretrained_model_name_or_path: str,
model_args = (),
kwargs = {}
)
classmethod
nemo_automodel.components.models.hy_v3.model.HYV3ForCausalLM.get_input_embeddings()
nemo_automodel.components.models.hy_v3.model.HYV3ForCausalLM.get_output_embeddings()
nemo_automodel.components.models.hy_v3.model.HYV3ForCausalLM.initialize_weights(
buffer_device: torch.device | None = None,
dtype: torch.dtype = torch.bfloat16
) -> None
nemo_automodel.components.models.hy_v3.model.HYV3ForCausalLM.set_input_embeddings(
value
)
nemo_automodel.components.models.hy_v3.model.HYV3ForCausalLM.set_output_embeddings(
new_embeddings
)
nemo_automodel.components.models.hy_v3.model.HYV3ForCausalLM.update_moe_gate_bias() -> None
class nemo_automodel.components.models.hy_v3.model.HYV3Model(
config: typing.Any,
backend: nemo_automodel.components.models.common.BackendConfig,
moe_config: nemo_automodel.components.moe.config.MoEConfig | None = None,
moe_overrides: dict | None = None
)

Bases: Module

embed_tokens
head_dim
layers
= torch.nn.ModuleDict()
max_seq_len
= config.max_position_embeddings
moe_config
= moe_config or MoEConfig(**moe_defaults)
norm
rotary_emb
nemo_automodel.components.models.hy_v3.model.HYV3Model.forward(
input_ids: torch.Tensor,
position_ids: torch.Tensor | None = None,
attention_mask: torch.Tensor | None = None,
padding_mask: torch.Tensor | None = None,
attn_kwargs: typing.Any = {}
) -> torch.Tensor
nemo_automodel.components.models.hy_v3.model.HYV3Model.init_weights(
buffer_device: torch.device | None = None
) -> None
nemo_automodel.components.models.hy_v3.model.ModelClass = HYV3ForCausalLM