Skip to content

fix bugs, fix CP init.#14

Merged
yzhangcs merged 3 commits intofla-org:mainfrom
rakkit:main
Feb 23, 2025
Merged

fix bugs, fix CP init.#14
yzhangcs merged 3 commits intofla-org:mainfrom
rakkit:main

Conversation

@rakkit
Copy link
Copy Markdown
Contributor

@rakkit rakkit commented Feb 23, 2025

  1. Fix torchtian import bugs as they change api name
  2. Patch Fp8 as torchtitan has a bug which may lead to error
  3. Fix CP init, now we can get correct position_ids to transformer to do CP.

Summary by CodeRabbit

  • New Features

    • Enhanced handling for Float8 operations in the training workflow for improved precision.
  • Refactor / Style

    • Updated internal code formatting and organization to boost readability and maintain consistency.
    • Reformatted import statements for better clarity across multiple files.

rakkit added 2 commits February 23, 2025 20:26
2.Patch Fp8 as torchtitan has a bug which may lead to error
3. Fix CP init, now we can get correct position_ids to transformer to do CP.
2.Patch Fp8 as torchtitan has a bug which may lead to error
3. Fix CP init, now we can get correct position_ids to transformer to do CP.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 23, 2025

Walkthrough

The pull request updates several files to improve code clarity through formatting changes. In flame/checkpoint.py and flame/parallelisms/pipeline_fla.py, import statements and a function call have been reformatted into a multi-line style, with an updated import path for ParallelDims in the latter. In train.py, a new import for Float8Converter is added along with adjustments to logger messages, error handling, and a temporary workaround for float8 processing. No alterations to the control flow or external API exposure were made.

Changes

File(s) Change Summary
flame/checkpoint.py, flame/parallelisms/…/pipeline_fla.py Reorganized import statements into multi-line format; reformatted function calls; updated import path for ParallelDims in pipeline_fla.py; no changes to logic or control flow.
train.py Added Float8Converter import; reformatted logger info and error handling; applied a temporary workaround for float8 processing; standardized dataset attribute formatting.

Poem

Hi there, I'm a fuzzy coder bunny,
Hopping through the lines so clean and sunny.
Imports and logs now prance in a row,
With float8 magic making the code aglow.
Celebrate these tweaks with a joyful, hopping flow! 🐇🌸


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa43de0 and 0fdeec7.

📒 Files selected for processing (1)
  • train.py (16 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • train.py

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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. (Beta)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
train.py (2)

339-353: Track temporary float8 workaround.

A temporary workaround has been added to handle a bug in torchtitan that affects float8 processing when float8 is not enabled and torchao is not installed.

Would you like me to create an issue to track this temporary workaround and ensure it's removed once the bug is fixed in torchtitan?


619-621: Track float8 precomputation workaround.

The float8 dynamic scale precomputation for FSDP is part of the temporary workaround for the torchtitan bug.

Would you like me to create an issue to track this temporary workaround and ensure it's updated once the bug is fixed in torchtitan?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 09aa24d and fa43de0.

📒 Files selected for processing (3)
  • flame/checkpoint.py (2 hunks)
  • flame/parallelisms/pipeline_fla.py (2 hunks)
  • train.py (16 hunks)
✅ Files skipped from review due to trivial changes (2)
  • flame/checkpoint.py
  • flame/parallelisms/pipeline_fla.py
🧰 Additional context used
🪛 Ruff (0.8.2)
train.py

30-30: torchtitan.model_converter.build_model_converters imported but unused

Remove unused import: torchtitan.model_converter.build_model_converters

(F401)

🪛 GitHub Actions: pr
train.py

[error] 19-19: flake8: 'torchtitan.model_converter.build_model_converters' imported but unused (F401)

🔇 Additional comments (1)
train.py (1)

471-494: LGTM! Improved logging clarity.

The logging changes enhance readability and provide more comprehensive training progress information, including:

  • Sequence length
  • Gradient accumulation steps
  • Batch sizes
  • Total optimization steps
  • Warmup steps
  • Model parameters

Comment thread train.py Outdated
from flame.utils import device_module, device_type
from torchtitan.float8 import Float8Converter
from torchtitan.logging import init_logger, logger
from torchtitan.model_converter import build_model_converters
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused import.

The import build_model_converters from torchtitan.model_converter is not used in the code.

Apply this diff to fix the issue:

-from torchtitan.model_converter import build_model_converters
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from torchtitan.model_converter import build_model_converters
🧰 Tools
🪛 Ruff (0.8.2)

30-30: torchtitan.model_converter.build_model_converters imported but unused

Remove unused import: torchtitan.model_converter.build_model_converters

(F401)

Comment thread flame/checkpoint.py
from torchtitan.config_manager import TORCH_DTYPE_MAP, JobConfig
from torchtitan.logging import init_logger, logger
from torchtitan.optimizer import OptimizersContainer, SchedulersContainer
from torchtitan.optimizer import OptimizersContainer, LRSchedulersContainer
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actual Changes

Comment thread flame/checkpoint.py
model_parts: List[nn.Module],
optimizers: OptimizersContainer,
lr_schedulers: SchedulersContainer,
lr_schedulers: LRSchedulersContainer,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actual Changes

from torchtitan.parallelisms.pipelining_utils import (build_pipeline_schedule,
generate_split_points,
stage_ids_this_rank)
from torchtitan.parallelisms.pipeline import (
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actual Changes

Comment thread train.py
from flame.parallelisms.pipeline_fla import pipeline_fla
from flame.utils import device_module, device_type
from torchtitan.float8 import Float8Handler
from torchtitan.float8 import Float8Converter
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actual Changes

Comment thread train.py
# swap to Float8Linear based on float8 configs
float8_handler.convert_to_float8_training(model)
"""
# !TODO[flame]: torchtitan@57387af0e0e6173e7c0f3a38ac5db1134bb376d5 introduces a bug that cannot handel the case:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actual Changes.

If FP8 is not enabled, skipping the conversion to FP8 is better. Because if one did not install torchao, the FP8 Converter here might throw an error even if FP8 is not enabled.

Comment thread train.py
cp_buffers=[input_ids, labels] + [m.freqs_cis for m in model_parts],
cp_seq_dims=[1, 1] + [0 for _ in model_parts],
cp_no_restore_buffers={input_ids, labels},
cp_buffers=[input_ids, labels, position_ids],
Copy link
Copy Markdown
Contributor Author

@rakkit rakkit Feb 23, 2025

Choose a reason for hiding this comment

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

Actual Changes.

Now, position_ids can be distributed via CP.
A model with HF-Llama style can take position_ids and apply the correct rope.
(We still need to fix on FLA-Attention to correctly handle the position_ids)

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.

2 participants