Update train_efficient.py: auto-download from HF Hub for job env
Browse files- train_efficient.py +21 -3
train_efficient.py
CHANGED
|
@@ -24,14 +24,25 @@ from torch.distributions import Normal
|
|
| 24 |
# ============================================================
|
| 25 |
# Import the base agent as a module-level namespace
|
| 26 |
# ============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
sys.path.insert(0, '/app')
|
| 28 |
_BASE_NS = {}
|
| 29 |
-
exec(open(
|
| 30 |
print("Base agent loaded successfully.")
|
| 31 |
|
| 32 |
# Also create a separate namespace for the opponent
|
| 33 |
_OPP_NS = {}
|
| 34 |
-
exec(open(
|
| 35 |
|
| 36 |
from kaggle_environments import make as _make_env
|
| 37 |
|
|
@@ -608,10 +619,17 @@ def train():
|
|
| 608 |
if not best_path.exists():
|
| 609 |
best_path = final_path
|
| 610 |
if best_path.exists():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 611 |
sys.path.insert(0, '/app')
|
| 612 |
from generate_submission import generate_submission
|
| 613 |
generate_submission(
|
| 614 |
-
base_agent_path=
|
| 615 |
checkpoint_path=str(best_path),
|
| 616 |
output_path="/app/submission_adaptive.py",
|
| 617 |
)
|
|
|
|
| 24 |
# ============================================================
|
| 25 |
# Import the base agent as a module-level namespace
|
| 26 |
# ============================================================
|
| 27 |
+
# Download submission.py from HF Hub if not available locally
|
| 28 |
+
import urllib.request
|
| 29 |
+
_SUBMISSION_PATH = '/app/submission.py'
|
| 30 |
+
if not os.path.exists(_SUBMISSION_PATH):
|
| 31 |
+
print("Downloading submission.py from HF Hub...")
|
| 32 |
+
urllib.request.urlretrieve(
|
| 33 |
+
"https://huggingface.co/Builder-Neekhil/orbit-wars-agent/resolve/main/submission.py",
|
| 34 |
+
_SUBMISSION_PATH
|
| 35 |
+
)
|
| 36 |
+
print("Downloaded.")
|
| 37 |
+
|
| 38 |
sys.path.insert(0, '/app')
|
| 39 |
_BASE_NS = {}
|
| 40 |
+
exec(open(_SUBMISSION_PATH).read(), _BASE_NS)
|
| 41 |
print("Base agent loaded successfully.")
|
| 42 |
|
| 43 |
# Also create a separate namespace for the opponent
|
| 44 |
_OPP_NS = {}
|
| 45 |
+
exec(open(_SUBMISSION_PATH).read(), _OPP_NS)
|
| 46 |
|
| 47 |
from kaggle_environments import make as _make_env
|
| 48 |
|
|
|
|
| 619 |
if not best_path.exists():
|
| 620 |
best_path = final_path
|
| 621 |
if best_path.exists():
|
| 622 |
+
# Download generate_submission.py from HF Hub
|
| 623 |
+
gen_script = '/app/generate_submission.py'
|
| 624 |
+
if not os.path.exists(gen_script):
|
| 625 |
+
urllib.request.urlretrieve(
|
| 626 |
+
"https://huggingface.co/Builder-Neekhil/orbit-wars-agent/resolve/main/generate_submission.py",
|
| 627 |
+
gen_script
|
| 628 |
+
)
|
| 629 |
sys.path.insert(0, '/app')
|
| 630 |
from generate_submission import generate_submission
|
| 631 |
generate_submission(
|
| 632 |
+
base_agent_path=_SUBMISSION_PATH,
|
| 633 |
checkpoint_path=str(best_path),
|
| 634 |
output_path="/app/submission_adaptive.py",
|
| 635 |
)
|