Publish credential-free structural-smoke runner
Browse files
config/benching/fable-router-training-campaign.v1.json
CHANGED
|
@@ -78,6 +78,7 @@
|
|
| 78 |
"microBatch": 1,
|
| 79 |
"gradientLossScale": 1024,
|
| 80 |
"gradientCheckpointing": true,
|
|
|
|
| 81 |
"expertResidency": "cpu_offload_active_experts",
|
| 82 |
"minimumFreeDiskGiB": 18,
|
| 83 |
"privateResultRepo": "Swordnael/LFM2.5-Fable-Router-Smoke-Evidence",
|
|
|
|
| 78 |
"microBatch": 1,
|
| 79 |
"gradientLossScale": 1024,
|
| 80 |
"gradientCheckpointing": true,
|
| 81 |
+
"checkpointExpertResiduals": true,
|
| 82 |
"expertResidency": "cpu_offload_active_experts",
|
| 83 |
"minimumFreeDiskGiB": 18,
|
| 84 |
"privateResultRepo": "Swordnael/LFM2.5-Fable-Router-Smoke-Evidence",
|
training/fable_router_hybrid.py
CHANGED
|
@@ -16,6 +16,7 @@ from typing import Any, Iterator
|
|
| 16 |
import torch
|
| 17 |
import torch.nn as nn
|
| 18 |
import torch.nn.functional as F
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
PROJECTIONS = ("gate_proj", "up_proj", "down_proj")
|
|
@@ -124,6 +125,7 @@ class FrozenExpertRouterBlock(nn.Module):
|
|
| 124 |
self.top_k = top_k
|
| 125 |
self.maximum_scale = float(maximum_scale)
|
| 126 |
self.enabled = True
|
|
|
|
| 127 |
self._forced_expert: int | None = None
|
| 128 |
self._forced_scale: float | None = None
|
| 129 |
self.last_trace: RouteTrace | None = None
|
|
@@ -232,6 +234,13 @@ class AugmentedHostLayer(nn.Module):
|
|
| 232 |
output = self.host_layer(hidden_states, *args, **kwargs)
|
| 233 |
if not isinstance(output, torch.Tensor):
|
| 234 |
raise TypeError(f"unsupported LFM2 layer output type: {type(output)!r}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
return self.expert_block(output)
|
| 236 |
|
| 237 |
|
|
|
|
| 16 |
import torch
|
| 17 |
import torch.nn as nn
|
| 18 |
import torch.nn.functional as F
|
| 19 |
+
from torch.utils.checkpoint import checkpoint
|
| 20 |
|
| 21 |
|
| 22 |
PROJECTIONS = ("gate_proj", "up_proj", "down_proj")
|
|
|
|
| 125 |
self.top_k = top_k
|
| 126 |
self.maximum_scale = float(maximum_scale)
|
| 127 |
self.enabled = True
|
| 128 |
+
self.checkpoint_enabled = False
|
| 129 |
self._forced_expert: int | None = None
|
| 130 |
self._forced_scale: float | None = None
|
| 131 |
self.last_trace: RouteTrace | None = None
|
|
|
|
| 234 |
output = self.host_layer(hidden_states, *args, **kwargs)
|
| 235 |
if not isinstance(output, torch.Tensor):
|
| 236 |
raise TypeError(f"unsupported LFM2 layer output type: {type(output)!r}")
|
| 237 |
+
if self.expert_block.checkpoint_enabled and self.training and torch.is_grad_enabled():
|
| 238 |
+
return checkpoint(
|
| 239 |
+
self.expert_block,
|
| 240 |
+
output,
|
| 241 |
+
use_reentrant=False,
|
| 242 |
+
preserve_rng_state=False,
|
| 243 |
+
)
|
| 244 |
return self.expert_block(output)
|
| 245 |
|
| 246 |
|
training/run_fable_router_full_bank_fit.py
CHANGED
|
@@ -211,6 +211,7 @@ def run(args: argparse.Namespace, result: dict[str, Any]) -> None:
|
|
| 211 |
)
|
| 212 |
block.materialize_experts(bank_path, layer, device=expert_device, dtype=dtype)
|
| 213 |
block.load_router_warmstart(warm_state[f"layers.{layer}.router.gate.weight"])
|
|
|
|
| 214 |
block.enabled = False
|
| 215 |
blocks.append(block)
|
| 216 |
print(f"materialized frozen bank layer {layer + 1}/{admission['layers']} on {expert_device}", flush=True)
|
|
@@ -230,6 +231,7 @@ def run(args: argparse.Namespace, result: dict[str, Any]) -> None:
|
|
| 230 |
raise RuntimeError(f"expected 60 router parameters, found {len(names)}")
|
| 231 |
for block in blocks:
|
| 232 |
block.enabled = True
|
|
|
|
| 233 |
model.zero_grad(set_to_none=True)
|
| 234 |
output = model(**batch, use_cache=False)
|
| 235 |
scale = float(admission["gradientLossScale"])
|
|
@@ -253,6 +255,7 @@ def run(args: argparse.Namespace, result: dict[str, Any]) -> None:
|
|
| 253 |
destination = Path(result["output"]) / "router-checkpoint.safetensors"
|
| 254 |
saved = router_state_dict(model)
|
| 255 |
save_file(saved, str(destination), metadata={"autonoma": "non-routing-full-bank-admission"})
|
|
|
|
| 256 |
with torch.inference_mode():
|
| 257 |
before = model(input_ids=batch["input_ids"], attention_mask=batch["attention_mask"], use_cache=False).logits.detach().cpu()
|
| 258 |
with torch.no_grad():
|
|
|
|
| 211 |
)
|
| 212 |
block.materialize_experts(bank_path, layer, device=expert_device, dtype=dtype)
|
| 213 |
block.load_router_warmstart(warm_state[f"layers.{layer}.router.gate.weight"])
|
| 214 |
+
block.checkpoint_enabled = bool(admission.get("checkpointExpertResiduals", False))
|
| 215 |
block.enabled = False
|
| 216 |
blocks.append(block)
|
| 217 |
print(f"materialized frozen bank layer {layer + 1}/{admission['layers']} on {expert_device}", flush=True)
|
|
|
|
| 231 |
raise RuntimeError(f"expected 60 router parameters, found {len(names)}")
|
| 232 |
for block in blocks:
|
| 233 |
block.enabled = True
|
| 234 |
+
model.train()
|
| 235 |
model.zero_grad(set_to_none=True)
|
| 236 |
output = model(**batch, use_cache=False)
|
| 237 |
scale = float(admission["gradientLossScale"])
|
|
|
|
| 255 |
destination = Path(result["output"]) / "router-checkpoint.safetensors"
|
| 256 |
saved = router_state_dict(model)
|
| 257 |
save_file(saved, str(destination), metadata={"autonoma": "non-routing-full-bank-admission"})
|
| 258 |
+
model.eval()
|
| 259 |
with torch.inference_mode():
|
| 260 |
before = model(input_ids=batch["input_ids"], attention_mask=batch["attention_mask"], use_cache=False).logits.detach().cpu()
|
| 261 |
with torch.no_grad():
|