Skip to content

fix enable_cache #4091

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

Merged
merged 8 commits into from
May 6, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update
  • Loading branch information
Jintao-Huang committed May 6, 2025
commit 85d7c45cc622cc9d5bcc536241f39486b2399ddd
18 changes: 13 additions & 5 deletions swift/utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from transformers.integrations import is_deepspeed_zero3_enabled
from transformers.utils import is_torch_cuda_available, is_torch_mps_available, is_torch_npu_available

from .env import get_dist_setting, is_dist, is_dist_ta, is_master
from .env import get_dist_setting, is_dist, is_dist_ta, is_local_master, is_master
from .logger import get_logger
from .utils import deep_getattr

Expand Down Expand Up @@ -232,11 +232,19 @@ def _cond(name, module):
@contextmanager
def safe_ddp_context(hash_id: Optional[str], use_barrier: bool = False):
if use_barrier and dist.is_initialized():
if (is_dist() or is_dist_ta()) and not is_master():
dist.barrier()
if (is_dist() or is_dist_ta()):
if not is_master():
dist.barrier()
if not is_local_master():
# Compatible with multi-machine scenarios,
# where each machine uses different storage hardware.
dist.barrier()
yield
if (is_dist() or is_dist_ta()) and is_master():
dist.barrier()
if (is_dist() or is_dist_ta()):
if is_master():
dist.barrier()
if is_local_master():
dist.barrier()
elif hash_id is not None:
lock_dir = os.path.join(get_cache_dir(), 'lockers')
os.makedirs(lock_dir, exist_ok=True)
Expand Down
Loading