Remove old submission_template.py
Browse files- submission_template.py +0 -51
submission_template.py
DELETED
|
@@ -1,51 +0,0 @@
|
|
| 1 |
-
"""Machine unlearning challenge - submission template.
|
| 2 |
-
|
| 3 |
-
Checks a submission locally (same loading rules as the server), then uploads it.
|
| 4 |
-
python submission_template.py submission.pt
|
| 5 |
-
Fill in SERVER_URL and API_KEY with the values you received from the organizers.
|
| 6 |
-
"""
|
| 7 |
-
import os
|
| 8 |
-
import sys
|
| 9 |
-
|
| 10 |
-
import torch
|
| 11 |
-
|
| 12 |
-
from task_template import build_model
|
| 13 |
-
|
| 14 |
-
SERVER_URL = "FILL_IN" # submission endpoint given by the organizers
|
| 15 |
-
API_KEY = "FILL_IN" # your team token
|
| 16 |
-
MAX_BYTES = 400 * 1024 * 1024
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
def check(path: str) -> None:
|
| 20 |
-
if not path.endswith((".pt", ".pth")):
|
| 21 |
-
raise SystemExit("File extension must be .pt or .pth")
|
| 22 |
-
if os.path.getsize(path) > MAX_BYTES:
|
| 23 |
-
raise SystemExit(f"File too large: limit {MAX_BYTES} bytes")
|
| 24 |
-
state = torch.load(path, map_location="cpu", weights_only=True) # must be a plain state dict
|
| 25 |
-
model = build_model()
|
| 26 |
-
model.load_state_dict(state, strict=True) # same keys and shapes as the original
|
| 27 |
-
bad = [k for k, v in state.items() if v.is_floating_point() and not torch.isfinite(v).all()]
|
| 28 |
-
if bad:
|
| 29 |
-
raise SystemExit(f"Non-finite values in: {bad[:5]}")
|
| 30 |
-
model.eval()
|
| 31 |
-
with torch.no_grad():
|
| 32 |
-
out = model(torch.zeros(2, 3, 224, 224))
|
| 33 |
-
if out.shape != (2, 100) or not torch.isfinite(out).all():
|
| 34 |
-
raise SystemExit("Model forward pass failed the sanity check")
|
| 35 |
-
print("local checks passed")
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
def submit(path: str) -> None:
|
| 39 |
-
if "FILL_IN" in (SERVER_URL, API_KEY):
|
| 40 |
-
raise SystemExit("Set SERVER_URL and API_KEY before submitting")
|
| 41 |
-
import requests
|
| 42 |
-
with open(path, "rb") as f:
|
| 43 |
-
r = requests.post(SERVER_URL, headers={"X-API-Key": API_KEY}, files={"file": (os.path.basename(path), f)}, timeout=1800)
|
| 44 |
-
print(r.status_code, r.text)
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
if __name__ == "__main__":
|
| 48 |
-
if len(sys.argv) != 2:
|
| 49 |
-
raise SystemExit(f"usage: python {sys.argv[0]} <submission.pt>")
|
| 50 |
-
check(sys.argv[1])
|
| 51 |
-
submit(sys.argv[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|