Skip to content

Commit 14f14cd

Browse files
authored
fix: AC silently skipped on all registered VLMs — flatten ModuleList (#1941)
fix: flatten ModuleList in _extract_model_layers so AC applies to individual layers _reduce_attrs returns ModuleList objects as single items; extending layers with them meant AC code never found self_attn/mlp on a ModuleList and silently skipped all checkpointing. Flatten any ModuleList results so layers contains individual decoder layers, matching the heuristic path. Signed-off-by: khazic <khazzz1c@gmail.com>
1 parent 388845e commit 14f14cd

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

nemo_automodel/components/distributed/parallelizer.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,12 +1307,19 @@ def _reduce_attrs(model, fqns: List[str]) -> List[nn.Module]:
13071307

13081308
MODEL_CLS_TO_LAYERS = VLM_MODEL_CLS_TO_LAYERS | LLM_MODEL_CLS_TO_LAYERS
13091309

1310+
def _extend_layers(layers, modules):
1311+
for m in modules:
1312+
if isinstance(m, nn.ModuleList):
1313+
layers.extend(m)
1314+
else:
1315+
layers.append(m)
1316+
13101317
model_cls = type(model)
13111318
layers: List[nn.Module] = []
13121319
if model_cls in MODEL_CLS_TO_LAYERS:
1313-
layers.extend(_reduce_attrs(model, MODEL_CLS_TO_LAYERS[model_cls]))
1320+
_extend_layers(layers, _reduce_attrs(model, MODEL_CLS_TO_LAYERS[model_cls]))
13141321
elif model_cls.__name__ in MODEL_CLS_TO_LAYERS:
1315-
layers.extend(_reduce_attrs(model, MODEL_CLS_TO_LAYERS[model_cls.__name__]))
1322+
_extend_layers(layers, _reduce_attrs(model, MODEL_CLS_TO_LAYERS[model_cls.__name__]))
13161323
elif hasattr(model, "model") and hasattr(model.model, "layers"):
13171324
# Default case for all other models (assumed to be a causal LM)
13181325
if isinstance(model.model.layers, nn.ModuleDict):

0 commit comments

Comments
 (0)