File size: 6,119 Bytes
4a3c89d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | import torch
import requests
import sys
import os
# --------------------------------
# LOADING THE GRADIENTS
# --------------------------------
"""
Gradient contents (gradients/model{i}.pt):
- "gradients": dict {parameter_name -> gradient tensor}, mirroring the
model's named_parameters()
- "family": "mlp", "cnn", or "vit"
- "activation": "relu" | "tanh" | "sigmoid" | "gelu"
- "feature_shape": (C, H, W) per-image input feature shape
- "batch_size": 128
"""
grad = torch.load(os.path.join("gradients", "model1.pt"), weights_only=False)
print("gradient file keys:", list(grad))
print(" family:", grad["family"], "| activation:", grad["activation"],
"| feature_shape:", grad["feature_shape"], "| batch_size:", grad["batch_size"])
print(" gradient tensors:")
for name, g in grad["gradients"].items():
print(f" {name:14} {tuple(g.shape)}")
# --------------------------------
# LOADING THE MODEL (white-box)
# --------------------------------
"""
Model contents (models/model{i}.pt):
A plain state_dict {parameter_name -> weight tensor}
Further information regarding the model can be found in the corresponding gradient file.
"""
state = torch.load(os.path.join("models", "model1.pt"), weights_only=False)
print("\nmodel state_dict keys:", list(state))
for name, w in state.items():
print(f" {name:14} {tuple(w.shape)}")
# --------------------------------
# SUBMISSION FORMAT
# --------------------------------
"""
The submission must be a .pt file that torch.load()s to a dict with EXACTLY
the keys "model1" ... "model12". Each value is a tensor of your reconstructed
images for that model:
- shape: (128, 3, 64, 64)
- dtype: float32
- pixel values in the [0, 1] range
The 128 images do not have to be in any particular order: each is matched to
the nearest ground-truth image (one-to-one, no reuse) and scored by SSIM.
"""
# Example submission:
submission = {
f"model{i}": torch.rand(128, 3, 64, 64, dtype=torch.float32) # values in [0, 1]
for i in range(1, 12 + 1)
}
torch.save(submission, "example_submission.pt")
# --------------------------------
# SUBMISSION PROCESS
# --------------------------------
"""
FL Audit Task β Participant Submission Guide
========================================================
You will upload a single **.pt** file that torch.load()s to a dictionary with
keys **model1** through **model12**, each mapping to a tensor of 128
reconstructed images. The evaluator loads your file, runs shape/dtype/range
checks, and then scores it against the private ground-truth images.
Follow these rules carefully to avoid automatic rejection.
1) File format
--------------
- **Extension:** `.pt` (a Torch-saved dictionary)
- **Content:** must contain EXACTLY the keys `model1`, `model2`, ..., `model12`
(no more, no fewer; note: no underscore).
- **Max file size:** 300 MB (hard limit). Larger files are rejected.
2) Per-model tensor requirements
--------------------------------
Each value `submission["model{i}"]` must be:
- **Shape:** exactly `(128, 3, 64, 64)`.
- **Dtype:** a floating-point tensor (it is cast to float32).
- **Range:** all pixel values in `[0, 1]`.
- **Finite:** no NaN or Inf values.
3) Scoring
----------
For each model your 128 images are matched one-to-one (no reuse) to that model's
128 private images via a Hungarian assignment that maximises the total SSIM (the
matching is done per model, not across models). Your score is the mean matched-pair
SSIM. During the hackathon the leaderboard shows your score on a fixed 30% subset of
the images; the final ranking uses the held-out 70%.
4) Typical failure messages & what they mean
--------------------------------------------
- "File extension must be .pt (a torch-saved dict of model1..model12)."
β Wrong extension.
- "Submission must be a dict with keys 'model1'..'model12', got a ..."
β The file did not load to a dictionary.
- "Missing key(s): [...]." / "Unexpected key(s): [...]."
β Your keys are not exactly model1..model12.
- "model{i}: images must have shape (128, 3, 64, 64), got (...)."
β Shape mismatch (wrong count or resolution -- remember to upsample to 64x64).
- "model{i}: images must be a float tensor (dtype ... given)."
β Submit float images, not uint8/integers.
- "model{i}: pixel values must be in [0, 1], got min ... max ..."
β Rescale your images into [0, 1].
- "model{i}: images contain NaN or Inf values."
β Clean up invalid values before submitting.
- "File too large: limit 314572800 bytes."
β Your file exceeds 300 MB.
"""
BASE_URL = "http://35.192.205.84"
API_KEY = "YOUR_API_KEY_HERE"
TASK_ID = "21-fl-audit"
FILE_PATH = "example_submission.pt"
SUBMIT = False # set True to actually upload FILE_PATH
def die(msg):
print(f"{msg}", file=sys.stderr)
sys.exit(1)
if not SUBMIT:
print("SUBMIT is False -- set SUBMIT = True (and your API_KEY/FILE_PATH) to upload.")
sys.exit(0)
if not os.path.isfile(FILE_PATH):
die(f"File not found: {FILE_PATH}")
try:
with open(FILE_PATH, "rb") as f:
files = {
"file": (os.path.basename(FILE_PATH), f, "application/octet-stream"),
}
resp = requests.post(
f"{BASE_URL}/submit/{TASK_ID}",
headers={"X-API-Key": API_KEY},
files=files,
timeout=(10, 120),
)
try:
body = resp.json()
except Exception:
body = {"raw_text": resp.text}
if resp.status_code == 413:
die("Upload rejected: file too large (HTTP 413). Reduce size and try again.")
resp.raise_for_status()
submission_id = body.get("submission_id")
print("Successfully submitted.")
print("Server response:", body)
if submission_id:
print(f"Submission ID: {submission_id}")
except requests.exceptions.RequestException as e:
detail = getattr(e, "response", None)
print(f"Submission error: {e}")
if detail is not None:
try:
print("Server response:", detail.json())
except Exception:
print("Server response (text):", detail.text)
sys.exit(1)
|