Safer usage of mkdir across the project

This commit is contained in:
oobabooga 2025-06-17 07:09:33 -07:00
parent 8689d7ecea
commit 0d1597616f
16 changed files with 240 additions and 206 deletions

View file

@ -241,7 +241,8 @@ def backup_adapter(input_folder):
# Create the new subfolder
subfolder_path = Path(f"{input_folder}/{creation_date_str}")
subfolder_path.mkdir(parents=True, exist_ok=True)
if not subfolder_path.exists():
subfolder_path.mkdir(parents=True, exist_ok=True)
# Check if the file already exists in the subfolder
backup_adapter_file = Path(f"{input_folder}/{creation_date_str}/adapter_model.bin")
@ -676,7 +677,9 @@ def do_train(lora_name: str, always_override: bool, q_proj_en: bool, v_proj_en:
decoded_entries.append({"value": decoded_text})
# Write the log file
Path('user_data/logs').mkdir(exist_ok=True)
if not Path('user_data/logs').exists():
Path('user_data/logs').mkdir(exist_ok=True)
with open(Path('user_data/logs/train_dataset_sample.json'), 'w') as json_file:
json.dump(decoded_entries, json_file, indent=4)