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

fix signal_file_path to avoid race condition #1253

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion llmfoundry/data/finetuning/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
import logging
import os
import random
import hashlib
from typing import Any, Dict, Optional, Tuple, Union

import torch
Expand Down Expand Up @@ -532,9 +534,11 @@ def _download_remote_hf_dataset(remote_path: str, split: str) -> str:

# Since we don't know exactly what the extension will be, since it is one of a list
# use a signal file to wait for instead of the desired file
random_number = random.randint(0, 999999)
sha_signature = hashlib.sha256(str(random_number).encode()).hexdigest()
signal_file_path = os.path.join(
finetune_dir,
f'.node_{dist.get_node_rank()}_local_rank0_completed',
f'.sha_{sha_signature}_completed',
)
if dist.get_local_rank() == 0:
try:
Expand Down
6 changes: 5 additions & 1 deletion llmfoundry/data/finetuning/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def preprocessing_fn(example: Dict) -> Dict[str, str]:
import importlib
import logging
import os
import random
import hashlib
import warnings
from collections.abc import Mapping
from functools import partial
Expand Down Expand Up @@ -814,7 +816,9 @@ def build_from_hf(
Returns:
Dataset: The tokenized dataset.
"""
signal_file_path = f'.node_{dist.get_node_rank()}_local_rank0_data_prep_completed'
random_number = random.randint(0, 999999)
sha_signature = hashlib.sha256(str(random_number).encode()).hexdigest()
signal_file_path = f'.sha_{sha_signature}_data_prep_completed'

# Non local rank 0 ranks will wait here for local rank 0 to finish the data processing.
# Once local rank 0 is done, the datasets are all cached on disk, and all other ranks
Expand Down
6 changes: 5 additions & 1 deletion llmfoundry/models/hf/hf_causal_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import logging
import os
import random
import hashlib
import warnings
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -339,7 +341,9 @@ def _autoset_attn_implementation_monkeypatch(
f'init_device="{init_device}" must be either "cpu" or "meta".',
)

signal_file_path = f'.node_{dist.get_node_rank()}_local_rank0_completed'
random_number = random.randint(0, 999999)
sha_signature = hashlib.sha256(str(random_number).encode()).hexdigest()
signal_file_path = f'.sha_{sha_signature}_completed'
if dist.get_local_rank() == 0:
with open(signal_file_path, 'wb') as f:
f.write(b'local_rank0_completed_download')
Expand Down
6 changes: 5 additions & 1 deletion llmfoundry/utils/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import functools
import logging
import os
import random
import hashlib
import re
from collections import OrderedDict
from typing import (
Expand Down Expand Up @@ -453,7 +455,9 @@ def build_tokenizer(
os.environ['TRANSFORMERS_NO_ADVISORY_WARNINGS'] = '1'
os.environ['TOKENIZERS_PARALLELISM'] = 'false'

signal_file_path = f'.node_{dist.get_node_rank()}_local_rank0_completed_tokenizer_setup'
random_number = random.randint(0, 999999)
sha_signature = hashlib.sha256(str(random_number).encode()).hexdigest()
signal_file_path = f'.sha_{sha_signature}_completed_tokenizer_setup'

if dist.is_available() and dist.is_initialized(
) and dist.get_world_size() > 1:
Expand Down
Loading