verl icon indicating copy to clipboard operation
verl copied to clipboard

verl.model_merger cannot convert Qwen3_5ForConditionalGeneration Megatron checkpoints to HuggingFace format

Open khazic opened this issue 8 months ago • 4 comments

Summary

verl.model_merger does not currently support converting Megatron checkpoints for Qwen3_5ForConditionalGeneration into HuggingFace format, even though Qwen3.5-related training paths appear to be partially supported in the codebase.

What I am trying to do

Convert a Megatron SFT checkpoint saved by verl into HuggingFace format with:

torchrun \
  --nnodes 1 \
  --nproc_per_node 1 \
  --master_addr 127.0.0.1 \
  --master_port 29631 \
  -m verl.model_merger merge \
  --backend megatron \
  --local_dir <checkpoint_dir> \
  --target_dir <output_dir> \
  --tie-word-embedding \
  --trust-remote-code \
  --use_cpu_initialization

The checkpoint directory has the standard Megatron layout expected by the merger, including:

  • dist_ckpt/
  • data_0.pt, data_1.pt, ...

Problem

The merger fails for Qwen3_5ForConditionalGeneration.

There seem to be two separate issues:

1. Qwen3_5Config compatibility in merger path

The merger assumes top-level config fields such as:

  • num_hidden_layers
  • hidden_size
  • num_attention_heads
  • num_key_value_heads
  • intermediate_size

But for Qwen3_5Config, these are stored under text_config.

This causes failures like:

AttributeError: 'Qwen3_5Config' object has no attribute 'num_hidden_layers'

2. Missing registry support for Qwen3_5ForConditionalGeneration

After patching the config shape manually, the merger still fails with:

NotImplementedError: Model Type: Qwen3_5ForConditionalGeneration not supported.

From the current code, Qwen3_5ForConditionalGeneration is not registered in the merger registries used by verl.model_merger, including:

  • SupportedModel
  • MODEL_CONFIG_CONVERTER_REGISTRY
  • MODEL_INITIALIZER_REGISTRY
  • MODEL_WEIGHT_CONVERTER_REGISTRY

Relevant code observations

In verl/models/mcore/registry.py:

  • some newer VLM names are recognized elsewhere in the codebase
  • but verl.model_merger still relies on SupportedModel and the old registries
  • Qwen3_5ForConditionalGeneration is missing there

In verl/model_merger/megatron_model_merger.py:

  • merger logic directly reads self.hf_config.num_hidden_layers
  • this is incompatible with configs where text model fields live under text_config

Expected behavior

verl.model_merger should be able to convert Megatron checkpoints for Qwen3_5ForConditionalGeneration to HuggingFace format, or at minimum clearly document that this architecture is not yet supported.

Actual behavior

Conversion fails before loading and merging finishes, due to:

  1. config field assumptions incompatible with Qwen3_5Config
  2. missing model registration for Qwen3_5ForConditionalGeneration

Suggested fix

Support Qwen3_5ForConditionalGeneration in the Megatron merger path by:

  1. Making merger and config conversion handle text_config.* for Qwen3.5 VLM configs
  2. Registering Qwen3_5ForConditionalGeneration in:
    • SupportedModel
    • MODEL_CONFIG_CONVERTER_REGISTRY
    • MODEL_INITIALIZER_REGISTRY
    • MODEL_WEIGHT_CONVERTER_REGISTRY
  3. Ensuring weight conversion logic is available for this architecture

Notes

This issue is specifically about Megatron checkpoint -> HuggingFace conversion. It is not about checkpoint saving itself: the checkpoint directory already contains a valid dist_ckpt/ layout.

khazic avatar Mar 16 '26 03:03 khazic

Did you use mbridge?

vermouth1992 avatar Mar 16 '26 08:03 vermouth1992

I guess you will have to use mbridge where model_merger is not necessary

vermouth1992 avatar Mar 16 '26 08:03 vermouth1992

As @vermouth1992 mentioned, using mbridge is the recommended approach for Qwen3.5 VLM models. The model_merger path is primarily for legacy workflows.

With mbridge:

  1. Set actor_rollout_ref.actor.megatron.use_mbridge=True during training
  2. Use mbridge's save_hf_model API directly to export to HuggingFace format
  3. No separate merger step needed

However, if you need to use model_merger for existing checkpoints without mbridge:

  1. Config access: Modify megatron_model_merger.py to handle nested text_config:
# Instead of:
num_layers = self.hf_config.num_hidden_layers
# Use:
num_layers = getattr(self.hf_config, 'num_hidden_layers', None) or \
             getattr(self.hf_config, 'text_config', {}).get('num_hidden_layers')
  1. Registry support: Add Qwen3_5ForConditionalGeneration to the registries

This is a valid gap in the merger support for newer VLM architectures. Consider contributing a PR if you implement the fix.

Kirrito-k423 avatar Mar 17 '26 11:03 Kirrito-k423

As @vermouth1992 mentioned, using mbridge is the recommended approach for Qwen3.5 VLM models. The model_merger path is primarily for legacy workflows.如前所述,使用 mbridge 是 Qwen3.5 VLM 模型的推荐方法。model_merger 路径主要用于遗留工作流。

With mbridge:  与 mbridge 合作:

  1. Set actor_rollout_ref.actor.megatron.use_mbridge=True during training设置 actor_rollout_ref.actor.megatron.use_mbridge=训练期间为真
  2. Use mbridge's save_hf_model API directly to export to HuggingFace format直接使用 mbridge 的 save_hf_model API 导出为 HuggingFace 格式
  3. No separate merger step needed无需单独的合并步骤

However, if you need to use model_merger for existing checkpoints without mbridge:不过,如果你需要用 model_merger 来管理没有 mbridge 的现有检查点:

  1. Config access: Modify megatron_model_merger.py to handle nested text_config:**配置访问 **:修改 megatron_model_merger.py 以处理嵌套的 text_config:

Instead of:

num_layers = self.hf_config.num_hidden_layers

Use:

num_layers = getattr(self.hf_config, 'num_hidden_layers', None) or
getattr(self.hf_config, 'text_config', {}).get('num_hidden_layers') 2. Registry support: Add Qwen3_5ForConditionalGeneration to the registries**注册表支持 **:向注册表添加 Qwen3_5ForConditionalGeneration

This is a valid gap in the merger support for newer VLM architectures. Consider contributing a PR if you implement the fix.这是新 VLM 架构合并支持中的一个有效空白。如果你实施修复,考虑贡献一个公共关系。

As @vermouth1992 mentioned, using mbridge is the recommended approach for Qwen3.5 VLM models. The model_merger path is primarily for legacy workflows.

With mbridge:

  1. Set actor_rollout_ref.actor.megatron.use_mbridge=True during training
  2. Use mbridge's save_hf_model API directly to export to HuggingFace format
  3. No separate merger step needed

However, if you need to use model_merger for existing checkpoints without mbridge:

  1. Config access: Modify megatron_model_merger.py to handle nested text_config:

Instead of:

num_layers = self.hf_config.num_hidden_layers

Use:

num_layers = getattr(self.hf_config, 'num_hidden_layers', None) or
getattr(self.hf_config, 'text_config', {}).get('num_hidden_layers') 2. Registry support: Add Qwen3_5ForConditionalGeneration to the registries

This is a valid gap in the merger support for newer VLM architectures. Consider contributing a PR if you implement the fix.

May I ask if you can share the MBridge merge script? My MBridge version is 0.15.1 and does not have the savehf_model API. I always encounter errors when using AutoBridge to merge

FangdongWang avatar Apr 16 '26 04:04 FangdongWang