Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,9 @@ from huggingface_hub import whoami
|
|
| 5 |
from huggingface_hub import HfApi
|
| 6 |
is_spaces = True if os.environ.get("SPACE_ID") else False
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
if is_spaces:
|
| 9 |
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
|
| 10 |
import spaces
|
|
@@ -280,6 +283,24 @@ def start_training(
|
|
| 280 |
print(f"Added HF_TOKEN secret to {new_space_id}")
|
| 281 |
except Exception as e:
|
| 282 |
print(f"Failed to add HF_TOKEN secret to new space: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
|
| 284 |
cmd = f"autotrain spacerunner --project-name {slugged_lora_name} --script-path {dataset_folder}"
|
| 285 |
cmd += f" --username {profile.username} --token {hf_token} --backend spaces-l4x1"
|
|
|
|
| 5 |
from huggingface_hub import HfApi
|
| 6 |
is_spaces = True if os.environ.get("SPACE_ID") else False
|
| 7 |
|
| 8 |
+
import tempfile
|
| 9 |
+
from git import Repo
|
| 10 |
+
|
| 11 |
if is_spaces:
|
| 12 |
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
|
| 13 |
import spaces
|
|
|
|
| 283 |
print(f"Added HF_TOKEN secret to {new_space_id}")
|
| 284 |
except Exception as e:
|
| 285 |
print(f"Failed to add HF_TOKEN secret to new space: {e}")
|
| 286 |
+
|
| 287 |
+
# Clone the subspace repo and push the dataset files into it
|
| 288 |
+
with tempfile.TemporaryDirectory() as clone_dir:
|
| 289 |
+
subspace_repo_url = f"https://{hf_token}@huggingface.co/spaces/{new_space_id}"
|
| 290 |
+
repo = Repo.clone_from(subspace_repo_url, clone_dir)
|
| 291 |
+
|
| 292 |
+
# Copy all dataset_folder contents to the clone dir
|
| 293 |
+
for item in os.listdir(dataset_folder):
|
| 294 |
+
s = os.path.join(dataset_folder, item)
|
| 295 |
+
d = os.path.join(clone_dir, item)
|
| 296 |
+
if os.path.isdir(s):
|
| 297 |
+
shutil.copytree(s, d, dirs_exist_ok=True)
|
| 298 |
+
else:
|
| 299 |
+
shutil.copy2(s, d)
|
| 300 |
+
|
| 301 |
+
repo.index.add(["."])
|
| 302 |
+
repo.index.commit("Push training files from controller")
|
| 303 |
+
repo.remote().push()
|
| 304 |
|
| 305 |
cmd = f"autotrain spacerunner --project-name {slugged_lora_name} --script-path {dataset_folder}"
|
| 306 |
cmd += f" --username {profile.username} --token {hf_token} --backend spaces-l4x1"
|