Skip to content

Commit 309d147

Browse files
rrutmannCopilot
andcommitted
fix: Write to unique filenames
Co-authored-by: Copilot <copilot@github.com>
1 parent 2126b0b commit 309d147

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎tests/fsdp2_parallelization/test_tensor_parallelism.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
from tests.utility import find_free_port
2121

2222

23-
def patch_config_file(original_config_path: Path, activation_type: str, tmp_dir: Path) -> Path:
23+
def patch_config_file(original_config_path: Path, activation_type: str, tmp_dir: Path, file_tag: str = "") -> Path:
2424
"""Patches the original configuration file to set a custom activation type."""
2525
with original_config_path.open("r", encoding="utf-8") as f:
2626
config_dict = yaml.safe_load(f)
2727

2828
config_dict["model_raw"]["config"]["activation_type"] = activation_type
2929

30-
tmp_file_path = tmp_dir / original_config_path.name
30+
file_suffix = f"_{file_tag}" if file_tag else ""
31+
tmp_file_path = tmp_dir / f"{original_config_path.stem}{file_suffix}{original_config_path.suffix}"
3132
with tmp_file_path.open("w", encoding="utf-8") as f:
3233
yaml.safe_dump(config_dict, f)
3334

@@ -103,12 +104,16 @@ def _test_tp_sharding_impl(
103104
):
104105
# Seed before FSDP2 instantiation
105106
torch.manual_seed(42)
106-
fsdp2_path = patch_config_file(fsdp2_config_path, activation_type, tmp_config_dir)
107+
fsdp2_path = patch_config_file(
108+
fsdp2_config_path, activation_type, tmp_config_dir, file_tag=f"{activation_type}_rank{process_id}_fsdp2"
109+
)
107110
fsdp2_model, fsdp2_mesh = self._get_components(fsdp2_path, tmp_path)
108111

109112
# Seed again before TP instantiation to match
110113
torch.manual_seed(42)
111-
tp_path = patch_config_file(tp_config_path, activation_type, tmp_config_dir)
114+
tp_path = patch_config_file(
115+
tp_config_path, activation_type, tmp_config_dir, file_tag=f"{activation_type}_rank{process_id}_tp"
116+
)
112117
tp_model, tp_mesh = self._get_components(tp_path, tmp_path)
113118

114119
# Ensure models use the correct MLP

0 commit comments

Comments
 (0)