Support heterogeneous NemotronHPuzzle model (#32549)
Signed-off-by: <dafrimi@nvidia.com> Signed-off-by: Daniel Afrimi <dafrimi@nvidia.com> Signed-off-by: root <dafrimi@nvidia.com>
This commit is contained in:
@@ -81,6 +81,26 @@ class ModelArchConfigConvertorBase:
|
||||
self.hf_text_config, attributes, default_factory=default_factory
|
||||
)
|
||||
|
||||
def get_num_experts_from_block_configs(self) -> int:
|
||||
"""Check block_configs for heterogeneous models (e.g., NemotronH).
|
||||
|
||||
For heterogeneous models with varying expert counts per layer,
|
||||
returns the MAX to ensure all expert weights can be loaded.
|
||||
"""
|
||||
max_experts = 0
|
||||
block_configs = getattr(self.hf_text_config, "block_configs", None)
|
||||
if block_configs:
|
||||
for block in block_configs:
|
||||
if isinstance(block, dict):
|
||||
if block.get("block_type", "") == "moe":
|
||||
max_experts = max(max_experts, block.get("n_routed_experts", 0))
|
||||
else:
|
||||
if getattr(block, "block_type", "") == "moe":
|
||||
max_experts = max(
|
||||
max_experts, getattr(block, "n_routed_experts", 0)
|
||||
)
|
||||
return max_experts
|
||||
|
||||
def get_num_experts(self) -> int:
|
||||
"""Returns the number of experts in the model."""
|
||||
num_expert_names = [
|
||||
@@ -89,13 +109,16 @@ class ModelArchConfigConvertorBase:
|
||||
"n_routed_experts", # DeepSeek
|
||||
"num_local_experts", # Mixtral
|
||||
]
|
||||
|
||||
num_experts = getattr_iter(self.hf_text_config, num_expert_names, 0)
|
||||
if isinstance(num_experts, list):
|
||||
# Ernie VL's remote code uses list[int]...
|
||||
# The values are always the same so we just take the first one.
|
||||
return num_experts[0]
|
||||
# Coerce to 0 if explicitly set to None
|
||||
return num_experts or 0
|
||||
|
||||
if not num_experts:
|
||||
num_experts = self.get_num_experts_from_block_configs()
|
||||
return num_experts
|
||||
|
||||
@final
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user