Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化finetune.py为混合精度训练. #33

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

mellivoraPKU
Copy link
Contributor

1.优化finetune.py为混合精度训练.
2.将finetune_distributed.py分布式训练方式改为deepspeed,同时相应开启混合训练.
3.更新requirements.txt到最新版本

finetune.py Outdated
outputs = model(**inputs, labels=labels)

# Automatic Mixed Precision (AMP) context manager for efficient training.
# Inside this context, `torch.is_autocast_enabled()` returns True; outside the context, it returns False.
Copy link
Owner

@zhangfaen zhangfaen Jan 24, 2025

Choose a reason for hiding this comment

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

Inside this context, torch.is_autocast_enabled() returns True; outside the context, it returns False.

This line should be changed to below

AMP context manager can be embeded by another AMP context manager, the behavior is shown by below code snippet.

# import torch
# from torch.amp import autocast

# with autocast(device_type='cuda', dtype=torch.bfloat16):
   # print(torch.is_autocast_enabled()) # True

    # with autocast(device_type='cuda', dtype=torch.bfloat16):
      # print(torch.is_autocast_enabled()) # True

    # with autocast(device_type='cuda', dtype=torch.bfloat16, enabled=False):
      # print(torch.is_autocast_enabled()) # False
  
    # print(torch.is_autocast_enabled()) # True

2.将finetune_distributed.py分布式训练方式改为deepspeed,同时相应开启混合训练.
3.更新requirements.txt到最新版本
@zhangfaen zhangfaen merged commit 986ff95 into zhangfaen:main Jan 24, 2025
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