modelscope / modelscope/ms-swift
Qwen3-VL-8B-Instruct megatron finetune报错IndexError: index 36 is out of range
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 1.7k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 136
Description
Describe the bug
File "xxxx/Megatron-LM-core_v0.13.1/megatron/core/tensor_parallel/random.py", line 477, in checkpoint
[rank122]: return CheckpointFunction.apply(function, distribute_saved_activations, *args)
[rank122]: File "/usr/local/lib/python3.10/site-packages/torch/autograd/function.py", line 575, in apply
[rank122]: return super().apply(*args, **kwargs) # type: ignore[misc]
[rank122]: File "xxx/Megatron-LM-core_v0.13.1/megatron/core/tensor_parallel/random.py", line 423, in forward
[rank122]: outputs = run_function(*args)
[rank122]: File "xxx/swift_0916/swift_251015/swift/megatron/model/mm_gpt/qwen3_vl.py", line 217, in custom_forward
[rank122]: layer = self._get_layer(index)
[rank122]: File "xxx/Megatron-LM-core_v0.13.1/megatron/core/transformer/transformer_block.py", line 361, in _get_layer
[rank122]: return self.layers[layer_number]
[rank122]: File "/usr/local/lib/python3.10/site-packages/torch/nn/modules/container.py", line 334, in getitem
[rank122]: return self._modules[self._get_abs_string_index(idx)]
[rank122]: File "/usr/local/lib/python3.10/site-packages/torch/nn/modules/container.py", line 316, in _get_abs_string_index
[rank122]: raise IndexError(f"index {idx} is out of range")
[rank122]: IndexError: index 36 is out of range
从模型的config来看,num_hidden_layers为36,实际megatron会读取超过这个数字
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with swift/megatron/model/mm_gpt/qwen3_vl.py at custom_forward and compare its layer index handling with Megatron-LM-core_v0.13.1/megatron/core/transformer/transformer_block.py, especially _get_layer. Reproduce the Qwen3-VL-8B-Instruct finetuning failure and trace why index 36 is requested when num_hidden_layers is 36; done means the run no longer raises this out-of-range error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100