move eval bundle download to be lazy and inside the python code so that we can substantially simplify the run bash scripts
This commit is contained in:
+10
-4
@@ -58,7 +58,7 @@ def get_base_dir():
|
||||
os.makedirs(nanochat_dir, exist_ok=True)
|
||||
return nanochat_dir
|
||||
|
||||
def download_file_with_lock(url, filename):
|
||||
def download_file_with_lock(url, filename, postprocess_fn=None):
|
||||
"""
|
||||
Downloads a file from a URL to a local path in the base directory.
|
||||
Uses a lock file to prevent concurrent downloads among multiple ranks.
|
||||
@@ -76,18 +76,24 @@ def download_file_with_lock(url, filename):
|
||||
# All other ranks block until it is released
|
||||
fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX)
|
||||
|
||||
# Recheck after acquiring lock (another process may have downloaded it)
|
||||
if os.path.exists(file_path):
|
||||
return file_path
|
||||
|
||||
# Download the content as bytes
|
||||
print(f"Downloading {url}...")
|
||||
with urllib.request.urlopen(url) as response:
|
||||
content = response.read().decode('utf-8')
|
||||
content = response.read() # bytes
|
||||
|
||||
with open(file_path, 'w') as f:
|
||||
# Write to local file
|
||||
with open(file_path, 'wb') as f:
|
||||
f.write(content)
|
||||
|
||||
print(f"Downloaded to {file_path}")
|
||||
|
||||
# Run the postprocess function if provided
|
||||
if postprocess_fn is not None:
|
||||
postprocess_fn(file_path)
|
||||
|
||||
# Clean up the lock file after the lock is released
|
||||
try:
|
||||
os.remove(lock_path)
|
||||
|
||||
Reference in New Issue
Block a user