verl icon indicating copy to clipboard operation
verl copied to clipboard

[fsdp] FSDP wrap policy raises on partial-resolution `_no_split_modules` (Qwen3.5 / Qwen3-Next case)

Open SteadfastAsArt opened this issue 6 months ago • 2 comments

Summary

verl.utils.fsdp_utils.get_fsdp_wrap_policy raises an exception when any name in the model's _no_split_modules list cannot be resolved to a class on the model, even when other names in the list resolve fine and are sufficient to build a valid wrap policy. This breaks training for models whose HF config exposes forward-compat / partial layer names alongside the real classes.

Repro

Loading Qwen3.5-9B (e.g. via Qwen3_5VLForConditionalGeneration) yields:

>>> model._no_split_modules
['Qwen3_5DecoderLayer', 'Qwen3_5VisionBlock', 'Qwen3_5TextDecoderLayer']

With transformers==5.2.0, the first two are real exported classes, but Qwen3_5TextDecoderLayer is not. get_fsdp_wrap_policy(model) then dies with:

Exception: Could not find the transformer layer class to wrap in the model.

…even though Qwen3_5DecoderLayer is the real decoder layer and would suffice for a correct FSDP wrap policy.

Self-contained repro (no GPU, no model download):

import torch.nn as nn
from verl.utils.fsdp_utils import get_fsdp_wrap_policy

class RealLayer(nn.Module):
    def __init__(self): super().__init__(); self.lin = nn.Linear(4, 4)

class FakeModel(nn.Module):
    _no_split_modules = ["RealLayer", "DoesNotExistLayer"]
    def __init__(self):
        super().__init__()
        self.layer = RealLayer()

get_fsdp_wrap_policy(FakeModel())   # raises today; should succeed

Offending code

verl/utils/fsdp_utils.py:125-132 (current main):

elif fsdp_transformer_layer_cls_to_wrap is not None:
    transformer_cls_to_wrap = set()
    for layer_class in fsdp_transformer_layer_cls_to_wrap:
        transformer_cls = get_module_class_from_name(module, layer_class)
        if transformer_cls is None:
            raise Exception("Could not find the transformer layer class to wrap in the model.")
        else:
            transformer_cls_to_wrap.add(transformer_cls)

The loop demands strict resolution of every name. Any single missing entry kills the whole policy.

Why this is brittle

HF transformers ships _no_split_modules lists that may include forward-compat / not-yet-exported class names — this is normal upstream practice to leave room for future refactors. verl shouldn't insist they all resolve. As long as at least one resolves to a real class, the FSDP wrap policy is well-defined.

This already bites Qwen3.5 today, and a similar pattern is likely for other multimodal / next-gen Qwen variants (e.g. Qwen3-Next, where text/vision decoder names are split across versions).

Proposed fix

Make resolution lenient: skip names that don't resolve, raise only if none do. Log a warning listing the skipped names so users see what happened.

elif fsdp_transformer_layer_cls_to_wrap is not None:
    transformer_cls_to_wrap = set()
    missing_classes = []
    for layer_class in fsdp_transformer_layer_cls_to_wrap:
        transformer_cls = get_module_class_from_name(module, layer_class)
        if transformer_cls is None:
            missing_classes.append(layer_class)
        else:
            transformer_cls_to_wrap.add(transformer_cls)

    if not transformer_cls_to_wrap:
        raise Exception(
            f"Could not find any of the transformer layer classes to wrap in the model: "
            f"{fsdp_transformer_layer_cls_to_wrap}"
        )
    if missing_classes:
        logger.warning(
            "FSDP wrap: skipped missing layer class names %s, wrapping %s",
            missing_classes,
            {c.__name__ for c in transformer_cls_to_wrap},
        )

PR with this fix + a CPU unit test will follow.

Environment

  • verl: main (commit f31c1d98 at time of filing)
  • transformers: 5.2.0
  • torch: 2.6+
  • model: Qwen3.5-9B (Qwen3_5VLForConditionalGeneration)

SteadfastAsArt avatar May 09 '26 04:05 SteadfastAsArt

Worth noting this is the same pattern as huggingface/accelerate#2947 ...verl likely inherited it from there.

The difference is that accelerate's issue was triggered by model variants missing layers, whereas here it's a forward-compat class name in transformers 5.x that doesn't exist yet.

matdou avatar May 11 '26 13:05 matdou

It's also a problem for Gemma4 due to the distinction between the per-layer embedding models that have the additional Audio component and the 26B MoE and 31B Dense that are language and vision only (which therefore fail as a result).

nanastassacos avatar May 11 '26 14:05 nanastassacos