Skip to content

fix(sequence_parallel): do not write absent input tensors into SP inputs - #425

Open
ys2025-AI wants to merge 2 commits into
modelscope:dev-swift-v5from
ys2025-AI:fix/sp-text-inputs-embeds-none
Open

ys2025-AI wants to merge 2 commits into
modelscope:dev-swift-v5from
ys2025-AI:fix/sp-text-inputs-embeds-none

Conversation

@ys2025-AI

Copy link
Copy Markdown
Collaborator

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

Summary

Fix a bug in SequenceParallel._split_model_inputs: it wrote absent input tensors back as present keys (inputs_embeds=None). PEFT's causal-LM forward binds that key and then drops input_ids when delegating to the base model, so Qwen3_5Model receives neither input and raises:

ValueError: You must specify exactly one of input_ids or inputs_embeds

The root cause is the SP input-key handling, not removing / not loading multimodal weights. The language_model_only setup is only one way to reach the text-only SP path and expose the bug; the failure happens in the input plumbing before any vision weights are involved.

Changes

  • Only keep input keys that are actually present after the SP split:
    • pop inputs_embeds when the split result is None;
    • set inputs_embeds only when it has a value;
    • keep input_ids only when it has a value.
  • The multimodal path with _defer_inputs=True is unchanged: when inputs_embeds exists it is still written back.
  • Apply the repository pre-commit formatter/linter to the touched file.

Reproduction

  • Model: Qwen3.5-4B
  • Hardware: 4×Ascend A2 NPU, dp_size=2, fsdp_size=2, ulysses_size=2
  • Training: LoRA, language_model_only=true, text-only dataset (used only as a reproducer for the text-SP path)
  • Before: first forward raises the input_ids / inputs_embeds error
  • After: the log shows vision tower stripped by language_model_only, running the text-only SP path and training runs normally

Validation

  • SP + language_model_only 20-step run: first-step loss identical to the non-SP baseline; 20-step max difference 3.59e-3 (same order as NPU run-to-run nondeterminism).
  • Resident memory drops by ~171.8 MB/rank with the tower stripped.
  • Non-SP and SP-without-flag paths show no regression.
  • tests/transformers/test_sequence_parallel_and_cp.py -k "language_model_only or sp_runs_text": 1 passed.
  • tests/model/test_language_model_only.py: 6 passed.
  • pre-commit run --files src/twinkle/model/transformers/strategy/sequence_parallel/__init__.py: all hooks pass.
  • ruff check / ruff format --check: pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant