|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import hashlib |
3 | 4 | import importlib.util |
4 | 5 | from pathlib import Path |
5 | 6 |
|
@@ -103,7 +104,9 @@ def test_od_objectives_layout_reference_and_hooks(objective: str, n: int, zero1: |
103 | 104 | seen = [[] for _ in range(n)] |
104 | 105 |
|
105 | 106 | def hook(ctx: TraceContext, x: torch.Tensor) -> torch.Tensor: |
106 | | - raw = x.detach().cpu().contiguous().reshape(-1).view(torch.uint8).numpy().tobytes() |
| 107 | + raw = hashlib.sha256( |
| 108 | + x.detach().cpu().contiguous().reshape(-1).view(torch.uint8).numpy() |
| 109 | + ).digest() |
107 | 110 | seen[ctx.rank].append((ctx, raw)) |
108 | 111 | return x |
109 | 112 |
|
@@ -121,7 +124,9 @@ def hook(ctx: TraceContext, x: torch.Tensor) -> torch.Tensor: |
121 | 124 | repeated = [[] for _ in range(n)] |
122 | 125 |
|
123 | 126 | def capture(ctx: TraceContext, x: torch.Tensor) -> torch.Tensor: |
124 | | - raw = x.detach().cpu().contiguous().reshape(-1).view(torch.uint8).numpy().tobytes() |
| 127 | + raw = hashlib.sha256( |
| 128 | + x.detach().cpu().contiguous().reshape(-1).view(torch.uint8).numpy() |
| 129 | + ).digest() |
125 | 130 | repeated[ctx.rank].append((ctx, raw)) |
126 | 131 | return x |
127 | 132 |
|
@@ -133,9 +138,9 @@ def capture(ctx: TraceContext, x: torch.Tensor) -> torch.Tensor: |
133 | 138 | if objective != "mlm": |
134 | 139 | mlm = TrainConfig.from_manifest_v2(od_manifest("mlm", 1, False)) |
135 | 140 | extended = extend_params(init_params(mlm.model), cfg.model) |
136 | | - assert all( |
137 | | - torch.equal(extended[k], init_params(mlm.model)[k]) for k in init_params(mlm.model) |
138 | | - ) |
| 141 | + # One independent re-init, not one per key: od-base init is ~3 s. |
| 142 | + stage_a = init_params(mlm.model) |
| 143 | + assert all(torch.equal(extended[k], stage_a[k]) for k in stage_a) |
139 | 144 | pots = emulate( |
140 | 145 | n, |
141 | 146 | lambda c: honeypot_island(Honeypot(w.training.coord_pubkey, "honest"), w, c, theta, a, get), |
|