Skip to content

use skip_move_to_device for all cases#3015

Merged
winglian merged 2 commits into
mainfrom
skip-move-to-device
Aug 6, 2025
Merged

use skip_move_to_device for all cases#3015
winglian merged 2 commits into
mainfrom
skip-move-to-device

Conversation

@winglian

@winglian winglian commented Aug 5, 2025

Copy link
Copy Markdown
Collaborator

Description

WIP

multigpu tests https://github.com/axolotl-ai-cloud/axolotl/actions/runs/16738721812

Motivation and Context

How has this been tested?

Screenshots (if appropriate)

Types of changes

Social Handles (Optional)

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added an experimental option to control whether models are moved to the device before sharding.

@coderabbitai

coderabbitai Bot commented Aug 5, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

An optional configuration field experimental_skip_move_to_device was added to the model input schema. The _build_model method in src/axolotl/loaders/model.py was updated to conditionally override the skip_move_to_device flag based on this configuration, without changing other logic or method signatures.

Changes

Cohort / File(s) Change Summary
Model loading logic update
src/axolotl/loaders/model.py
Modified _build_model to override skip_move_to_device based on self.cfg.experimental_skip_move_to_device if set.
Schema update for experimental flag
src/axolotl/utils/schemas/model.py
Added optional boolean field experimental_skip_move_to_device to ModelInputConfig with description for experimental use.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

ready to merge

Suggested reviewers

  • djsaunde

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 788d50a and 1561fe6.

📒 Files selected for processing (2)
  • src/axolotl/loaders/model.py (1 hunks)
  • src/axolotl/utils/schemas/model.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/axolotl/utils/schemas/model.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/axolotl/loaders/model.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch skip-move-to-device

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab49d16 and 788d50a.

📒 Files selected for processing (1)
  • src/axolotl/loaders/model.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: NanoCode012
PR: axolotl-ai-cloud/axolotl#2854
File: README.md:73-77
Timestamp: 2025-07-02T02:56:20.788Z
Learning: For Axolotl Docker commands, the `--ipc=host` flag should be included by default to prevent shared memory failures that commonly occur with PyTorch DataLoaders and multiprocessing during machine learning training workflows.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: PyTest from Source Dist (3.11, 2.7.0)
  • GitHub Check: PyTest from Source Dist (3.11, 2.7.1)
  • GitHub Check: pre-commit
  • GitHub Check: PyTest (3.11, 2.7.1)
  • GitHub Check: PyTest from Source Dist (3.11, 2.6.0)
  • GitHub Check: pre-commit
  • GitHub Check: PyTest (3.11, 2.6.0)
  • GitHub Check: PyTest (3.11, 2.7.0)

Comment thread src/axolotl/loaders/model.py Outdated
self.model._tp_size = self.cfg.tensor_parallel_size
self.model._device_mesh = self.model_kwargs["device_mesh"]

skip_move_to_device = True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the impact of unconditionally skipping device movement.

This change overrides all the existing conditional logic for device placement, forcing skip_move_to_device = True in all scenarios. While this may resolve specific device placement issues, it could potentially break configurations that rely on the existing conditional logic.

Please run the following script to understand the existing device placement logic and verify this change won't cause regressions:

Consider a more targeted approach that addresses the specific issue without bypassing all existing logic. Could you clarify:

  1. What specific device placement issue is this change intended to resolve?
  2. Have you tested this change across different configurations (FSDP, DeepSpeed, multi-GPU, etc.)?
  3. Would a conditional approach be more appropriate than universally skipping device movement?

🏁 Script executed:

#!/bin/bash
# Description: Analyze the existing conditional logic for skip_move_to_device and its usage

# Find all places where skip_move_to_device is set to True conditionally
echo "=== Existing conditional logic for skip_move_to_device ==="
rg -A 2 -B 2 "skip_move_to_device = True" src/axolotl/loaders/model.py

echo -e "\n=== Usage of skip_move_to_device parameter ==="
rg -A 5 -B 2 "skip_move_to_device" src/axolotl/loaders/model.py

echo -e "\n=== Method that uses skip_move_to_device ==="
ast-grep --pattern $'def $_($$$, skip_move_to_device: $_) {
  $$$
}'

Length of output: 4620


Unconditional skip_move_to_device assignment bypasses all device‐placement logic

At src/axolotl/loaders/model.py:848, you’ve added:

skip_move_to_device = True

immediately before returning, which makes _build_model() always return True—regardless of any of the earlier, more granular conditions (FSDP CPU-efficient loading, QLoRA+FSDP, GPTQ, DeepSpeed Zero3, tensor parallelism workarounds, etc.). As a result, _apply_post_lora_load_setup will never move the model to the target device in any configuration.

• Impact

  • Overrides all existing logic that selectively skips device moves only when necessary
  • Forces all models to stay on their initial device, potentially breaking single-GPU or default-placement workflows and degrading performance in non‐specialized setups

• Requested changes

  1. Remove or scope this unconditional assignment so that you only skip moving the model under the specific conditions you intend to address.
  2. Clarify which device‐placement issue this change is meant to solve, and add targeted tests (FSDP, DeepSpeed, multi‐GPU, single‐GPU) to guard against regressions.

Please adjust the implementation to preserve the original conditional logic and only bypass model movement in the exact scenarios you’ve identified.

🤖 Prompt for AI Agents
In src/axolotl/loaders/model.py at line 848, the unconditional assignment
skip_move_to_device = True overrides all prior conditional logic for device
placement, causing models to never move to the target device. To fix this,
remove the unconditional assignment and instead set skip_move_to_device to True
only under the specific conditions that require skipping device moves,
preserving the original conditional checks for FSDP, QLoRA, DeepSpeed, and
tensor parallelism. Also, clarify in comments which device-placement issues are
addressed and add targeted tests for different configurations to prevent
regressions.

@codecov

codecov Bot commented Aug 5, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@NanoCode012

Copy link
Copy Markdown
Collaborator

What's the reason behind this change?

@winglian

winglian commented Aug 5, 2025

Copy link
Copy Markdown
Collaborator Author

What's the reason behind this change?

helps prevent oom when using FSDP+GRPO

@winglian winglian merged commit 8021c71 into main Aug 6, 2025
1 check passed
@winglian winglian deleted the skip-move-to-device branch August 6, 2025 04:13
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.

3 participants