Upload train_uv.py with huggingface_hub
Browse files- train_uv.py +52 -0
train_uv.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Elasticsearch Expert Model Training Script (UV Wrapper)
|
| 4 |
+
|
| 5 |
+
This script uses `uv` to manage dependencies on Hugging Face Jobs,
|
| 6 |
+
providing much faster and more reliable environment setup.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import subprocess
|
| 10 |
+
import sys
|
| 11 |
+
import os
|
| 12 |
+
|
| 13 |
+
def run_command(cmd):
|
| 14 |
+
print(f"Executing: {cmd}")
|
| 15 |
+
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
| 16 |
+
for line in process.stdout:
|
| 17 |
+
print(line, end="")
|
| 18 |
+
process.wait()
|
| 19 |
+
return process.returncode
|
| 20 |
+
|
| 21 |
+
def main():
|
| 22 |
+
print("=" * 50)
|
| 23 |
+
print("Elasticsearch Training Job - Environment Setup (UV)")
|
| 24 |
+
print("=" * 50)
|
| 25 |
+
|
| 26 |
+
# 1. Install uv
|
| 27 |
+
print("\nInstalling uv...")
|
| 28 |
+
if run_command("curl -LsSf https://astral.sh/uv/install.sh | sh") != 0:
|
| 29 |
+
print("Failed to install uv")
|
| 30 |
+
sys.exit(1)
|
| 31 |
+
|
| 32 |
+
# Add uv to path
|
| 33 |
+
os.environ["PATH"] = f"{os.path.expanduser('~/.local/bin')}:{os.environ['PATH']}"
|
| 34 |
+
|
| 35 |
+
# 2. Run training using uv
|
| 36 |
+
print("\nLaunching training script with uv...")
|
| 37 |
+
# We use 'uv run' which handles the virtualenv and dependencies automatically
|
| 38 |
+
# based on the requirements_train.txt or inline metadata.
|
| 39 |
+
# Here we'll pass the requirements file.
|
| 40 |
+
cmd = "uv run --with-requirements requirements_train.txt python train.py"
|
| 41 |
+
|
| 42 |
+
exit_code = run_command(cmd)
|
| 43 |
+
|
| 44 |
+
if exit_code == 0:
|
| 45 |
+
print("\nTraining completed successfully!")
|
| 46 |
+
else:
|
| 47 |
+
print(f"\nTraining failed with exit code {exit_code}")
|
| 48 |
+
|
| 49 |
+
sys.exit(exit_code)
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
main()
|