danil-e commited on
Commit
168aba3
·
verified ·
1 Parent(s): 77914b9

MLAgentBench protocol setup (improve a provided train.py); retire from-scratch tree

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +3 -0
  2. README.md +26 -18
  3. datasets/mlab-protocol/README.md +9 -0
  4. datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/Dockerfile +0 -0
  5. datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/data/answer.csv +0 -0
  6. datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/data/task_descriptor.txt +0 -0
  7. datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/data/test.csv +0 -0
  8. datasets/mlab-protocol/amp-parkinsons/environment/data/train.py +36 -0
  9. datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/data/train_clinical_data.csv +0 -0
  10. datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/data/train_peptides.csv +0 -0
  11. datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/data/train_proteins.csv +0 -0
  12. datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/prepare.py +3 -0
  13. datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/requirements.txt +0 -0
  14. datasets/mlab-protocol/amp-parkinsons/instruction.md +32 -0
  15. datasets/{mlab-real → mlab-protocol}/amp-parkinsons/task.toml +3 -3
  16. datasets/{mlab-real → mlab-protocol}/amp-parkinsons/tests/score.py +0 -0
  17. datasets/{mlab-real → mlab-protocol}/cifar10/environment/Dockerfile +0 -0
  18. datasets/{mlab-real → mlab-protocol}/cifar10/environment/data/answer.csv +0 -0
  19. datasets/{mlab-real → mlab-protocol}/cifar10/environment/data/test.csv +0 -0
  20. datasets/{mlab-real → mlab-protocol}/cifar10/environment/data/test_images.npy +0 -0
  21. datasets/{mlab-real → mlab-protocol}/cifar10/environment/data/train.csv +0 -0
  22. datasets/mlab-protocol/cifar10/environment/data/train.py +64 -0
  23. datasets/{mlab-real → mlab-protocol}/cifar10/environment/data/train_images.npy +0 -0
  24. datasets/{mlab-real → mlab-protocol}/cifar10/environment/prepare.py +3 -0
  25. datasets/{mlab-real → mlab-protocol}/cifar10/environment/requirements.txt +0 -0
  26. datasets/mlab-protocol/cifar10/instruction.md +25 -0
  27. datasets/{mlab-real → mlab-protocol}/cifar10/task.toml +2 -2
  28. datasets/{mlab-real → mlab-protocol}/cifar10/tests/score.py +0 -0
  29. datasets/{mlab-real/feedback → mlab-protocol/clrs}/environment/Dockerfile +0 -0
  30. datasets/{mlab-real/identify-contrails/environment/data/test/1002860788164505892/band_11.npy → mlab-protocol/clrs/environment/data/answer.npz} +2 -2
  31. datasets/{mlab-real/identify-contrails/environment/data/test/1002860788164505892/band_14.npy → mlab-protocol/clrs/environment/data/test.npz} +2 -2
  32. datasets/{mlab-real/identify-contrails/environment/data/test/1002860788164505892/band_15.npy → mlab-protocol/clrs/environment/data/train.npz} +2 -2
  33. datasets/mlab-protocol/clrs/environment/data/train.py +63 -0
  34. datasets/mlab-protocol/clrs/environment/prepare.py +12 -0
  35. datasets/mlab-protocol/clrs/environment/requirements.txt +5 -0
  36. datasets/mlab-protocol/clrs/instruction.md +24 -0
  37. datasets/mlab-protocol/clrs/task.toml +30 -0
  38. datasets/mlab-protocol/clrs/tests/score.py +47 -0
  39. datasets/{mlab-real → mlab-protocol}/dataset.toml +7 -3
  40. datasets/{mlab-real → mlab-protocol}/fathomnet/environment/Dockerfile +0 -0
  41. datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/answer.csv +0 -0
  42. datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/0020e399-6169-4bdb-b483-5400d13a630b.jpg +0 -0
  43. datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/0020ef94-baae-4358-b142-300a2dfac09f.jpg +0 -0
  44. datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/0047c1e2-44da-4b98-b848-cd6fa37571e0.jpg +0 -0
  45. datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/004ef158-293e-4177-9152-145e76f556f0.jpg +0 -0
  46. datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/00727ef4-3467-419c-9f7d-cb536a18d21d.jpg +0 -0
  47. datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/00e6cda4-6a64-4df5-a0da-a60ef5a5975e.jpg +0 -0
  48. datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/00f3b384-9ee3-4f73-a061-6303e11e7c17.jpg +0 -0
  49. datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/00ff96f5-26df-4b5e-bd51-3c39f02cb8fd.jpg +0 -0
  50. datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/01090eec-9292-48cb-aae8-d456e57af649.jpg +0 -0
.gitattributes CHANGED
@@ -62,3 +62,6 @@ datasets/mlab-real/imdb/environment/data/train.csv filter=lfs diff=lfs merge=lfs
62
  datasets/mlab-real/imdb-base/environment/data/train.csv filter=lfs diff=lfs merge=lfs -text
63
  datasets/mlab-real/amp-parkinsons/environment/data/train_peptides.csv filter=lfs diff=lfs merge=lfs -text
64
  datasets/mlab-real/imdb/environment/data/test.csv filter=lfs diff=lfs merge=lfs -text
 
 
 
 
62
  datasets/mlab-real/imdb-base/environment/data/train.csv filter=lfs diff=lfs merge=lfs -text
63
  datasets/mlab-real/amp-parkinsons/environment/data/train_peptides.csv filter=lfs diff=lfs merge=lfs -text
64
  datasets/mlab-real/imdb/environment/data/test.csv filter=lfs diff=lfs merge=lfs -text
65
+ datasets/mlab-protocol/amp-parkinsons/environment/data/train_peptides.csv filter=lfs diff=lfs merge=lfs -text
66
+ datasets/mlab-protocol/imdb/environment/data/test.csv filter=lfs diff=lfs merge=lfs -text
67
+ datasets/mlab-protocol/imdb/environment/data/train.csv filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,33 +1,41 @@
1
  # harbor-datasets-mlab
2
 
3
- Harbor-format **MLAB** benchmark (MLAgentBench, arXiv:2310.03302): 9 real ML tasks across tabular / text / vision / graph / segmentation (fathomnet + identify-contrails are ≤5 GB competition subsets, the rest full). A general benchmark for
4
- **any Harbor agent** — tasks are agent-neutral and **self-contained**.
5
- `registry.json` at the root, **one folder per task**.
 
 
 
 
6
 
7
  ## What each task contains
8
  ```
9
- datasets/mlab-real/<task>/
10
  environment/Dockerfile # builds FROM python:3.12-slim — no external base image
11
  environment/requirements.txt
12
- environment/prepare.py # stages the data into /workspace at build time
13
- environment/data/ # the real data
14
- instruction.md # task description + submission format (agent-neutral)
15
  tests/ # scorer + verifier
16
  task.toml # Harbor task config
17
  ```
18
- Nothing outside this repository is required: no private images, no extra repos,
19
- no tokens. `docker build` pulls only `python:3.12-slim` and public PyPI/apt
20
- packages. The agent is installed by Harbor itself, so any agent works.
 
 
21
 
22
- Tasks (`-i`): spaceship-titanic, house-price, amp-parkinsons, imdb, feedback, cifar10, ogbn-arxiv, fathomnet, identify-contrails.
 
 
 
 
 
 
 
 
23
 
24
  ## Run
25
  ```bash
26
- REPO=https://huggingface.co/datasets/danil-e/harbor-datasets-mlab
27
- harbor run --repo $REPO -d mlab-real -i feedback -a <agent> -m <model>
28
  ```
29
- The task image is built on first run (installs the task's Python stack, so the
30
- first build takes a few minutes; later runs reuse the cached image).
31
-
32
- Harbor's other environment backends (`-e ...`, e.g. for hosts without a Docker
33
- daemon) work the same way — see the Harbor documentation for their requirements.
 
1
  # harbor-datasets-mlab
2
 
3
+ Harbor-format **MLAgentBench** (arXiv:2310.03302), posed under the benchmark's own
4
+ protocol: every workspace already contains a `train.py` that runs end to end but
5
+ scores poorly, and the task is to **improve it** — not to solve the problem from an
6
+ empty directory. Task descriptions are MLAgentBench's `research_problem.txt` verbatim.
7
+
8
+ 10 tasks across tabular / text / vision / graph / segmentation / algorithmic. Agent-neutral
9
+ and self-contained: `registry.json` at the root, one folder per task.
10
 
11
  ## What each task contains
12
  ```
13
+ datasets/mlab-protocol/<task>/
14
  environment/Dockerfile # builds FROM python:3.12-slim — no external base image
15
  environment/requirements.txt
16
+ environment/prepare.py # stages the data AND train.py into /workspace at build time
17
+ environment/data/ # the real data + the starter train.py
18
+ instruction.md # research_problem.txt + submission format (agent-neutral)
19
  tests/ # scorer + verifier
20
  task.toml # Harbor task config
21
  ```
22
+ The answer key never reaches the workspace — `prepare.py` puts it aside in `/opt/mlab`,
23
+ where the scorer reads it.
24
+
25
+ Tasks: spaceship-titanic, house-price, amp-parkinsons, imdb, feedback, cifar10,
26
+ ogbn-arxiv, fathomnet, identify-contrails, clrs.
27
 
28
+ Data: 8 tasks full; fathomnet and identify-contrails are subsets sized to fit the
29
+ repository (identify-contrails is 155 records × 3 of 8 frames in float16, so its absolute
30
+ Dice is not comparable to the competition leaderboard); clrs is synthetic by construction,
31
+ from the official `dm-clrs` sampler.
32
+
33
+ ## Metrics
34
+ Each task is scored by the metric MLAgentBench's own `eval.py` uses: accuracy
35
+ (spaceship-titanic, imdb, cifar10, ogbn-arxiv), MAE (house-price), SMAPE (amp-parkinsons),
36
+ MCRMSE (feedback), MAP@20 (fathomnet), Dice (identify-contrails), pointer accuracy (clrs).
37
 
38
  ## Run
39
  ```bash
40
+ harbor run --local . mlab/house-price
 
41
  ```
 
 
 
 
 
datasets/mlab-protocol/README.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # mlab-protocol
2
+
3
+ One folder per task, posed the way MLAgentBench poses it: the workspace already
4
+ contains a `train.py` that runs end to end but scores poorly, and the task is to
5
+ improve it. The task description is MLAgentBench's own `research_problem.txt`.
6
+
7
+ Each task is self-contained — real data (`<task>/environment/data/`), a Dockerfile
8
+ building from `python:3.12-slim`, `instruction.md`, and a scorer in `tests/`.
9
+ The answer key never enters the workspace; `prepare.py` puts it aside in `/opt/mlab`.
datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/Dockerfile RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/data/answer.csv RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/data/task_descriptor.txt RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/data/test.csv RENAMED
File without changes
datasets/mlab-protocol/amp-parkinsons/environment/data/train.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ from sklearn.ensemble import RandomForestRegressor
4
+
5
+ TARGETS = ['updrs_1', 'updrs_2', 'updrs_3', 'updrs_4']
6
+
7
+
8
+ def smapep1(y_true, y_pred):
9
+ """SMAPE with +1 offset, as used by the competition (lower is better)."""
10
+ y_true = np.asarray(y_true, dtype=float) + 1
11
+ y_pred = np.clip(np.asarray(y_pred, dtype=float), 0, None) + 1
12
+ denom = (np.abs(y_true) + np.abs(y_pred)) / 2
13
+ return 100 * np.mean(np.abs(y_true - y_pred) / denom)
14
+
15
+
16
+ clinical = pd.read_csv('train_clinical_data.csv')
17
+ test = pd.read_csv('test.csv')
18
+
19
+ ## TODO: data cleaning and feature engineering
20
+ ## right now only visit_month is used as a feature
21
+
22
+ model = {}
23
+ for u in TARGETS:
24
+ df = clinical[['visit_month', u]].dropna()
25
+ X = df['visit_month'].values.reshape(-1, 1)
26
+ y = df[u].values
27
+ trained = RandomForestRegressor().fit(X, y)
28
+ model[u] = trained
29
+ print(f'{u}: train SMAPE = {smapep1(y, trained.predict(X)):.2f}')
30
+
31
+ months = test['visit_month'].values.reshape(-1, 1)
32
+ out = {'visit_id': test['visit_id'].values}
33
+ for u in TARGETS:
34
+ out[u] = model[u].predict(months)
35
+ pd.DataFrame(out).to_csv('submission.csv', index=False)
36
+ print('wrote submission.csv')
datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/data/train_clinical_data.csv RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/data/train_peptides.csv RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/data/train_proteins.csv RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/prepare.py RENAMED
@@ -7,5 +7,8 @@ for f in ['train_clinical_data.csv', 'train_proteins.csv', 'train_peptides.csv',
7
  if (SRC/f).exists(): shutil.copy(SRC/f, WS/f)
8
  for d in []:
9
  if (SRC/d).exists(): shutil.copytree(SRC/d, WS/d, dirs_exist_ok=True)
 
 
 
10
  shutil.copy(SRC/"answer.csv", ANS/"answer.csv")
11
  print("[prepare] staged", os.listdir(WS))
 
7
  if (SRC/f).exists(): shutil.copy(SRC/f, WS/f)
8
  for d in []:
9
  if (SRC/d).exists(): shutil.copytree(SRC/d, WS/d, dirs_exist_ok=True)
10
+ for f in ("train.py",):
11
+ if (SRC/f).exists(): shutil.copy(SRC/f, WS/f)
12
+
13
  shutil.copy(SRC/"answer.csv", ANS/"answer.csv")
14
  print("[prepare] staged", os.listdir(WS))
datasets/{mlab-real → mlab-protocol}/amp-parkinsons/environment/requirements.txt RENAMED
File without changes
datasets/mlab-protocol/amp-parkinsons/instruction.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # amp-parkinsons — improve the provided training script
2
+
3
+ Go through the data_description.txt file to understand the data and the machine learning task. You can summarize it in your research logs to keep track of what all you have to do. Then fill in the provided train.py script to train a model and iterate over different models or feature selections to get a better performance (for SMAPE score the lower is better). Finally, you should submit the predictions of your best model for the test set as a submission.csv as described in the evaluation_details.txt file.
4
+
5
+ ## Data (already staged in `/workspace`)
6
+ The files referenced by `train.py` are in the working directory. `train.py` runs as
7
+ provided.
8
+
9
+ ## Submission — REQUIRED
10
+ Write `submission.csv` with columns `visit_id,updrs_1,updrs_2,updrs_3,updrs_4`.
11
+
12
+ Scoring: **SMAPE** (LOWER is better) on a held-out split.
13
+
14
+ ## Valid submission — REQUIRED
15
+ Your predictions MUST come from a model fitted on the features. A constant submission
16
+ is not an answer, even if the metric happens to reward it: predictions have to vary
17
+ across rows, and for a multi-target problem across every target. Before writing the
18
+ file, print the number of distinct predicted values per column; if any column has
19
+ fewer than 10 distinct values, the model has collapsed — fix it rather than submit it.
20
+
21
+ ## Hardware — REQUIRED
22
+ Resolve the compute device with EXACTLY this snippet before training, and use it
23
+ for the model and for every batch:
24
+ ```python
25
+ import torch
26
+ DEVICE = ('cuda' if torch.cuda.is_available()
27
+ else 'mps' if torch.backends.mps.is_available() else 'cpu')
28
+ print('DEVICE=', DEVICE)
29
+ ```
30
+ Do **not** hardcode `'cuda'` and do **not** write a CUDA-only check like
31
+ `'cuda' if torch.cuda.is_available() else 'cpu'`: on a machine whose accelerator is
32
+ Apple MPS that silently falls back to CPU and training becomes far slower.
datasets/{mlab-real → mlab-protocol}/amp-parkinsons/task.toml RENAMED
@@ -3,14 +3,14 @@ artifacts = ["/workspace/submission.csv"]
3
 
4
  [task]
5
  name = "mlab/amp-parkinsons"
6
- description = "MLAgentBench amp-parkinsons — full competition data (SMAPE)"
7
- keywords = ["mlab", "mlagentbench", "tabular", "full-data"]
8
  [[task.authors]]
9
  name = "mlab"
10
 
11
  [metadata]
12
  family = "tabular"
13
- metric = "SMAPE"
14
 
15
  [verifier]
16
  timeout_sec = 1800.0
 
3
 
4
  [task]
5
  name = "mlab/amp-parkinsons"
6
+ description = "MLAgentBench amp-parkinsons — MLAgentBench protocol: improve the provided train.py"
7
+ keywords = ["mlab", "mlagentbench", "tabular", "full-data", "protocol"]
8
  [[task.authors]]
9
  name = "mlab"
10
 
11
  [metadata]
12
  family = "tabular"
13
+ metric = "smape"
14
 
15
  [verifier]
16
  timeout_sec = 1800.0
datasets/{mlab-real → mlab-protocol}/amp-parkinsons/tests/score.py RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/cifar10/environment/Dockerfile RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/cifar10/environment/data/answer.csv RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/cifar10/environment/data/test.csv RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/cifar10/environment/data/test_images.npy RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/cifar10/environment/data/train.csv RENAMED
File without changes
datasets/mlab-protocol/cifar10/environment/data/train.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ import torch
4
+ import torch.nn as nn
5
+ import torch.nn.functional as F
6
+ from torch.utils.data import TensorDataset, DataLoader
7
+
8
+ device = ('cuda' if torch.cuda.is_available()
9
+ else 'mps' if torch.backends.mps.is_available() else 'cpu')
10
+ print('DEVICE=', device)
11
+
12
+ X = np.load('train_images.npy').astype(np.float32) / 255.0
13
+ y = pd.read_csv('train.csv')['label'].values
14
+ Xte = np.load('test_images.npy').astype(np.float32) / 255.0
15
+ te_ids = pd.read_csv('test.csv')['id'].values
16
+
17
+ X = torch.tensor(X).permute(0, 3, 1, 2)
18
+ Xte = torch.tensor(Xte).permute(0, 3, 1, 2)
19
+ y = torch.tensor(y, dtype=torch.long)
20
+
21
+
22
+ class Net(nn.Module):
23
+ def __init__(self):
24
+ super().__init__()
25
+ self.conv1 = nn.Conv2d(3, 6, 5)
26
+ self.pool = nn.MaxPool2d(2, 2)
27
+ self.conv2 = nn.Conv2d(6, 16, 5)
28
+ self.fc1 = nn.Linear(16 * 5 * 5, 120)
29
+ self.fc2 = nn.Linear(120, 84)
30
+ self.fc3 = nn.Linear(84, 10)
31
+
32
+ def forward(self, x):
33
+ x = self.pool(F.relu(self.conv1(x)))
34
+ x = self.pool(F.relu(self.conv2(x)))
35
+ x = torch.flatten(x, 1)
36
+ x = F.relu(self.fc1(x))
37
+ x = F.relu(self.fc2(x))
38
+ return self.fc3(x)
39
+
40
+
41
+ model = Net().to(device)
42
+ optimizer = torch.optim.SGD(model.parameters(), lr=0.1, momentum=0.9)
43
+ criterion = nn.CrossEntropyLoss()
44
+ loader = DataLoader(TensorDataset(X, y), batch_size=128, shuffle=True)
45
+
46
+ epochs = 5
47
+ for epoch in range(epochs):
48
+ running = 0.0
49
+ for xb, yb in loader:
50
+ xb, yb = xb.to(device), yb.to(device)
51
+ optimizer.zero_grad()
52
+ loss = criterion(model(xb), yb)
53
+ loss.backward()
54
+ optimizer.step()
55
+ running += loss.item()
56
+ print(f'epoch {epoch} loss {running / len(loader):.4f}')
57
+
58
+ model.eval()
59
+ preds = []
60
+ with torch.no_grad():
61
+ for i in range(0, len(Xte), 512):
62
+ preds.append(model(Xte[i:i + 512].to(device)).argmax(1).cpu().numpy())
63
+ pd.DataFrame({'id': te_ids, 'label': np.concatenate(preds)}).to_csv('submission.csv', index=False)
64
+ print('wrote submission.csv')
datasets/{mlab-real → mlab-protocol}/cifar10/environment/data/train_images.npy RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/cifar10/environment/prepare.py RENAMED
@@ -7,5 +7,8 @@ for f in ("train.csv","test.csv"):
7
  shutil.copy(SRC/f, WS/f)
8
  for f in ("train_images.npy","test_images.npy","node_features.npy","edges.npy"):
9
  if (SRC/f).exists(): shutil.copy(SRC/f, WS/f)
 
 
 
10
  shutil.copy(SRC/"answer.csv", ANS/"answer.csv")
11
  print("[prepare] REAL mlab cifar10 (image 10-class, real split): staged", os.listdir(WS))
 
7
  shutil.copy(SRC/f, WS/f)
8
  for f in ("train_images.npy","test_images.npy","node_features.npy","edges.npy"):
9
  if (SRC/f).exists(): shutil.copy(SRC/f, WS/f)
10
+ for f in ("train.py",):
11
+ if (SRC/f).exists(): shutil.copy(SRC/f, WS/f)
12
+
13
  shutil.copy(SRC/"answer.csv", ANS/"answer.csv")
14
  print("[prepare] REAL mlab cifar10 (image 10-class, real split): staged", os.listdir(WS))
datasets/{mlab-real → mlab-protocol}/cifar10/environment/requirements.txt RENAMED
File without changes
datasets/mlab-protocol/cifar10/instruction.md ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # cifar10 — improve the provided training script
2
+
3
+ Given a training script on a dataset train.py, improve upon the current model performance (trained with current hyperparmeters in train.py). The training epochs should be within 10 to save time. Save per class probabilities for test set examples to submission.csv as shown in train.py.
4
+
5
+ ## Data (already staged in `/workspace`)
6
+ The files referenced by `train.py` are in the working directory. `train.py` runs as
7
+ provided.
8
+
9
+ ## Submission — REQUIRED
10
+ Write `submission.csv` with columns `id,label` — one predicted class index (0-9) per test image.
11
+
12
+ Scoring: **accuracy** (higher is better) on a held-out split.
13
+
14
+ ## Hardware — REQUIRED
15
+ Resolve the compute device with EXACTLY this snippet before training, and use it
16
+ for the model and for every batch:
17
+ ```python
18
+ import torch
19
+ DEVICE = ('cuda' if torch.cuda.is_available()
20
+ else 'mps' if torch.backends.mps.is_available() else 'cpu')
21
+ print('DEVICE=', DEVICE)
22
+ ```
23
+ Do **not** hardcode `'cuda'` and do **not** write a CUDA-only check like
24
+ `'cuda' if torch.cuda.is_available() else 'cpu'`: on a machine whose accelerator is
25
+ Apple MPS that silently falls back to CPU and training becomes far slower.
datasets/{mlab-real → mlab-protocol}/cifar10/task.toml RENAMED
@@ -2,8 +2,8 @@ schema_version = "1.3"
2
  artifacts = ["/workspace/submission.csv"]
3
  [task]
4
  name = "mlab/cifar10"
5
- description = "MLAgentBench CIFAR-10 (small) — image classification (timm / torchvision)"
6
- keywords = ["mlab", "mlagentbench", "image", "vision", "torchvision"]
7
  [[task.authors]]
8
  name = "mlab"
9
  [metadata]
 
2
  artifacts = ["/workspace/submission.csv"]
3
  [task]
4
  name = "mlab/cifar10"
5
+ description = "MLAgentBench CIFAR-10 (small) — MLAgentBench protocol: improve the provided train.py"
6
+ keywords = ["mlab", "mlagentbench", "image", "vision", "torchvision", "protocol"]
7
  [[task.authors]]
8
  name = "mlab"
9
  [metadata]
datasets/{mlab-real → mlab-protocol}/cifar10/tests/score.py RENAMED
File without changes
datasets/{mlab-real/feedback → mlab-protocol/clrs}/environment/Dockerfile RENAMED
File without changes
datasets/{mlab-real/identify-contrails/environment/data/test/1002860788164505892/band_11.npy → mlab-protocol/clrs/environment/data/answer.npz} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:21e2a1291fb41bd08fe9463635f51fbe7521342fc7575b3bc90343affc390cb0
3
- size 2097280
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ba0da261661fe4309243f42d578d7038b438c7daee17ce292af390b2d28c1495
3
+ size 2763560
datasets/{mlab-real/identify-contrails/environment/data/test/1002860788164505892/band_14.npy → mlab-protocol/clrs/environment/data/test.npz} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1452e19cdff9c724c87b0e0f3f726cc2cab9057f1e7dc1937edfd4fb8cffe2ea
3
- size 2097280
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa3d4880575957485b768f6ed3e502dbc0d3fc9d9a6723fe0398582cf0ea4dd1
3
+ size 4732006
datasets/{mlab-real/identify-contrails/environment/data/test/1002860788164505892/band_15.npy → mlab-protocol/clrs/environment/data/train.npz} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:df4b1ae667d8df133cf273193e5070d21c877d6b9c5856e9e27fcafc90059952
3
- size 2097280
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:92e8e16be35b3eddd0d1e707b5ba315ac5089d92afacf34be476b7ee789c8ba7
3
+ size 4295351
datasets/mlab-protocol/clrs/environment/data/train.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ import torch
4
+ import torch.nn as nn
5
+
6
+ device = ('cuda' if torch.cuda.is_available()
7
+ else 'mps' if torch.backends.mps.is_available() else 'cpu')
8
+ print('DEVICE=', device)
9
+
10
+ tr = np.load('train.npz')
11
+ te = np.load('test.npz')
12
+ A_tr, Pi_tr = tr['A'].astype(np.float32), tr['Pi'].astype(np.int64)
13
+ A_te = te['A'].astype(np.float32)
14
+ N_tr, N_te = A_tr.shape[1], A_te.shape[1]
15
+
16
+ epochs = 5 # weak baseline: scores each candidate from two edge weights only
17
+
18
+
19
+ class Baseline(nn.Module):
20
+ """For pair (i, j) and candidate k, score it from A[i, k] and A[k, j] alone."""
21
+
22
+ def __init__(self, hidden=32):
23
+ super().__init__()
24
+ self.net = nn.Sequential(nn.Linear(2, hidden), nn.ReLU(), nn.Linear(hidden, 1))
25
+
26
+ def forward(self, A): # A: (B, N, N)
27
+ B, N, _ = A.shape
28
+ ik = A.unsqueeze(2).expand(B, N, N, N) # A[b, i, k] over (i, j, k)
29
+ kj = A.unsqueeze(1).transpose(2, 3).expand(B, N, N, N) # A[b, k, j]
30
+ feat = torch.stack([ik, kj], dim=-1) # (B, N, N, N, 2)
31
+ return self.net(feat).squeeze(-1) # (B, N, N, N) logits over k
32
+
33
+
34
+ model = Baseline().to(device)
35
+ opt = torch.optim.Adam(model.parameters(), lr=1e-3)
36
+ lossf = nn.CrossEntropyLoss()
37
+
38
+ X, Y = torch.tensor(A_tr), torch.tensor(Pi_tr)
39
+ for epoch in range(epochs):
40
+ model.train()
41
+ perm = torch.randperm(len(X))
42
+ total, nb = 0.0, 0
43
+ for i in range(0, len(X), 32):
44
+ idx = perm[i:i + 32]
45
+ xb, yb = X[idx].to(device), Y[idx].to(device)
46
+ opt.zero_grad()
47
+ logits = model(xb) # (B, N, N, N)
48
+ loss = lossf(logits.reshape(-1, N_tr), yb.reshape(-1))
49
+ loss.backward()
50
+ opt.step()
51
+ total += loss.item(); nb += 1
52
+ print(f'epoch {epoch} loss {total / max(nb, 1):.4f}')
53
+
54
+ model.eval()
55
+ rows = []
56
+ with torch.no_grad():
57
+ for g in range(len(A_te)):
58
+ pred = model(torch.tensor(A_te[g:g + 1]).to(device)).argmax(-1)[0].cpu().numpy()
59
+ for r in range(N_te):
60
+ rows.append({'graph_id': g, 'row': r,
61
+ 'pointers': ' '.join(str(int(v)) for v in pred[r])})
62
+ pd.DataFrame(rows).to_csv('submission.csv', index=False)
63
+ print('wrote submission.csv')
datasets/mlab-protocol/clrs/environment/prepare.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Stage the CLRS task data into the workspace at build time."""
2
+ import os, shutil
3
+ from pathlib import Path
4
+ WS=Path(os.environ.get("MLAB_WORKSPACE","/workspace")); ANS=Path(os.environ.get("MLAB_ANSWER_DIR","/opt/mlab"))
5
+ SRC=Path("/opt/mlab/data"); WS.mkdir(parents=True,exist_ok=True); ANS.mkdir(parents=True,exist_ok=True)
6
+ for f in ("train.npz","test.npz"):
7
+ shutil.copy(SRC/f, WS/f)
8
+ for f in ("train.py",):
9
+ if (SRC/f).exists(): shutil.copy(SRC/f, WS/f)
10
+
11
+ shutil.copy(SRC/"answer.npz", ANS/"answer.npz")
12
+ print("[prepare] staged", os.listdir(WS))
datasets/mlab-protocol/clrs/environment/requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Graph / algorithmic-reasoning stack. torch is installed separately in the Dockerfile.
2
+ torch-geometric
3
+ scikit-learn
4
+ pandas
5
+ numpy<2
datasets/mlab-protocol/clrs/instruction.md ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # clrs — improve the provided training script
2
+
3
+ Improve the baseline model performance on the task floyd_warshall in The CLRS Algorithmic Reasoning Benchmark. To run the baseline model, execute train.py. You may modify the model architecture and the training loop, but keep the data loading and the submission format as provided.
4
+
5
+ ## Data (already staged in `/workspace`)
6
+ The files referenced by `train.py` are in the working directory.
7
+
8
+ ## Submission — REQUIRED
9
+ Write `submission.csv` with columns `graph_id,row,pointers` (64 space-separated predecessors per row).
10
+
11
+ Scoring: **pointer accuracy** (higher is better) on a held-out split.
12
+
13
+ ## Hardware — REQUIRED
14
+ Resolve the compute device with EXACTLY this snippet before training, and use it
15
+ for the model and for every batch:
16
+ ```python
17
+ import torch
18
+ DEVICE = ('cuda' if torch.cuda.is_available()
19
+ else 'mps' if torch.backends.mps.is_available() else 'cpu')
20
+ print('DEVICE=', DEVICE)
21
+ ```
22
+ Do **not** hardcode `'cuda'` and do **not** write a CUDA-only check like
23
+ `'cuda' if torch.cuda.is_available() else 'cpu'`: on a machine whose accelerator is
24
+ Apple MPS that silently falls back to CPU and training becomes far slower.
datasets/mlab-protocol/clrs/task.toml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ schema_version = "1.3"
2
+ artifacts = ["/workspace/submission.csv"]
3
+
4
+ [task]
5
+ name = "mlab/clrs"
6
+ description = "CLRS Algorithmic Reasoning (floyd_warshall) — MLAgentBench protocol: improve the provided train.py"
7
+ keywords = ["mlab", "clrs", "algorithmic-reasoning", "graph", "ood", "protocol"]
8
+ [[task.authors]]
9
+ name = "mlab"
10
+
11
+ [metadata]
12
+ family = "graph"
13
+ metric = "pointer_accuracy"
14
+
15
+ [verifier]
16
+ timeout_sec = 1800.0
17
+ collect = []
18
+ [verifier.env]
19
+
20
+ [agent]
21
+ timeout_sec = 7200.0
22
+
23
+ [environment]
24
+ network_mode = "public"
25
+ build_timeout_sec = 3600.0
26
+ os = "linux"
27
+ mcp_servers = []
28
+ [environment.env]
29
+
30
+ [solution.env]
datasets/mlab-protocol/clrs/tests/score.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Score a CLRS floyd_warshall submission: pointer accuracy against the reference Pi."""
2
+ import argparse, json, os
3
+ import numpy as np
4
+ import pandas as pd
5
+
6
+
7
+ def score(submission: str, answer: str):
8
+ Pi = np.load(answer)["Pi"] # (G, n, n) int
9
+ G, n, _ = Pi.shape
10
+ pred = np.full((G, n, n), -1, dtype=np.int64)
11
+ df = pd.read_csv(submission)
12
+ need = {"graph_id", "row", "pointers"}
13
+ if not need.issubset(df.columns):
14
+ raise ValueError(f"submission must have columns {sorted(need)}")
15
+ for gid, row, ptr in zip(df["graph_id"], df["row"], df["pointers"]):
16
+ g, i = int(gid), int(row)
17
+ if not (0 <= g < G and 0 <= i < n):
18
+ continue
19
+ vals = np.fromstring(str(ptr), sep=" ", dtype=np.int64)
20
+ if vals.size != n:
21
+ continue
22
+ pred[g, i] = vals
23
+ acc = float((pred == Pi).mean())
24
+ covered = float((pred >= 0).mean())
25
+ return acc, {"pointer_accuracy": acc, "coverage": covered, "graphs": float(G), "n": float(n)}
26
+
27
+
28
+ def main() -> int:
29
+ ap = argparse.ArgumentParser()
30
+ ap.add_argument("--submission", required=True)
31
+ ap.add_argument("--answer", required=True)
32
+ ap.add_argument("--reward-json", required=True)
33
+ a = ap.parse_args()
34
+ try:
35
+ reward, extra = score(a.submission, a.answer)
36
+ except Exception as exc: # noqa: BLE001 - always emit a reward
37
+ reward, extra = 0.0, {"error": str(exc)}
38
+ payload = {"reward": float(reward), **extra}
39
+ numeric = {k: v for k, v in payload.items() if isinstance(v, (int, float))} # Harbor: numeric only
40
+ os.makedirs(os.path.dirname(a.reward_json), exist_ok=True)
41
+ open(a.reward_json, "w").write(json.dumps(numeric))
42
+ print(payload)
43
+ return 0
44
+
45
+
46
+ if __name__ == "__main__":
47
+ raise SystemExit(main())
datasets/{mlab-real → mlab-protocol}/dataset.toml RENAMED
@@ -1,8 +1,8 @@
1
- # Dataset manifest for mlab-real
2
 
3
  [dataset]
4
- name = "mlab-real"
5
- version = "2.0"
6
 
7
  [[tasks]]
8
  name = "mlab/amp-parkinsons"
@@ -12,6 +12,10 @@ path = "amp-parkinsons"
12
  name = "mlab/cifar10"
13
  path = "cifar10"
14
 
 
 
 
 
15
  [[tasks]]
16
  name = "mlab/fathomnet"
17
  path = "fathomnet"
 
1
+ # Dataset manifest for mlab-protocol
2
 
3
  [dataset]
4
+ name = "mlab-protocol"
5
+ version = "1.0"
6
 
7
  [[tasks]]
8
  name = "mlab/amp-parkinsons"
 
12
  name = "mlab/cifar10"
13
  path = "cifar10"
14
 
15
+ [[tasks]]
16
+ name = "mlab/clrs"
17
+ path = "clrs"
18
+
19
  [[tasks]]
20
  name = "mlab/fathomnet"
21
  path = "fathomnet"
datasets/{mlab-real → mlab-protocol}/fathomnet/environment/Dockerfile RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/answer.csv RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/0020e399-6169-4bdb-b483-5400d13a630b.jpg RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/0020ef94-baae-4358-b142-300a2dfac09f.jpg RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/0047c1e2-44da-4b98-b848-cd6fa37571e0.jpg RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/004ef158-293e-4177-9152-145e76f556f0.jpg RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/00727ef4-3467-419c-9f7d-cb536a18d21d.jpg RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/00e6cda4-6a64-4df5-a0da-a60ef5a5975e.jpg RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/00f3b384-9ee3-4f73-a061-6303e11e7c17.jpg RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/00ff96f5-26df-4b5e-bd51-3c39f02cb8fd.jpg RENAMED
File without changes
datasets/{mlab-real → mlab-protocol}/fathomnet/environment/data/images/01090eec-9292-48cb-aae8-d456e57af649.jpg RENAMED
File without changes