sinkroute
Co-evolving Dual-LoRA and Mixture-of-Experts (MoE) Sink-Expert gradient routing to stop RLVR and GRPO reward hacking without capability collapse.
- License: MIT (
PEP 561typed, Python3.10+) - Paper & Empirical Benchmark: https://danielgaskins.com/sinkroute.html (PDF Preprint)
- Foundational RLVR Goodharting Study: https://danielgaskins.com/rlvr-latent-obfuscation.html
- Inference-Time Companion Runtime:
latchgate(pip install latchgate)
Why SinkRoute Exists
When post-training reasoning and coding models with Group Relative Policy Optimization (GRPO) against executable test harnesses (RLVR), unit-test loopholes allow low-effort exploits (R_proxy = 1, R_true = 0) to capture positive group advantages:
- Chain-of-Thought (
<think>) text penalties fail (0.0%covert recall): Policies sanitize<think>tokens while still emitting exploit shims in code. - Scalar mid-network linear probe penalties induce Neural Goodharting: Subtracting a frozen
57.1%-depth probe score fromR_proxyinverts probeAUROC(0.9994 -> 0.277) and cuts genuine coding solve rates in half (50%relative capability collapse,0.0%out-of-distribution solve rate). - Static subspace monitors and native MoE router masks drift or collapse capability: Across
1.5Bto30.5Bdense and fine-grained MoE models, on-policyGRPOrotates57.1%-depth shortcut representations by86.0 degto89.9 degaway fromstep=0calibration (2xfaster at7B), while statically masking high-exploit-MI native MoE experts causes+33.3%exploit rebound on64-expertOLMoEand a-50.0%held-out capability collapse (20.8% -> 10.4%) on128-expertQwen3-30B-A3B.
sinkroute solves all three failure modes in a drop-in training wrapper:
- Zero-ULP Value-Preserving Straight-Through Routing (
CoEvolvingDualLoRALinear&MoESinkWrapper): Forward passes evaluate bit-for-bit identically toW_base + MainAdapter:routed_delta = stop_grad(delta_main) + (1 - w) * (delta_main - stop_grad(delta_main)) + w * (delta_sink - stop_grad(delta_sink))This guarantees0.0importance-sampling discrepancy between rollout log-probs and policy updates,0.0deeper-layer co-adaptation shock whenSinkparameters are discarded at deployment, and exact(1 - w)vs.wgradient partitioning under gradient checkpointing (use_reentrant=False). - Token-Level Causal Sliding-Window Routing (
w_(b,t)): Preserves100%of honest<think>reasoning prefix gradients insideMainAdapterwhile routing localized code-exploit gradients intoSink, lifting small-scale (1.5B) held-outTrueSolveby3.5xover unmonitoredGRPOand7.0xover coarse sequence-pooledDual-LoRA. - Co-Evolving Confounder-Whitened Subspace (
CoEvolvingSubspaceTracker+MetamorphicCanary): Audits a sparse (10%-15%) subset of positive rollouts via clean-room AST metamorphic invariance checks (distinguishing genuineO(1)mathematical insight from harness spoofing) and updates the confounder-whitened positive-cone QR basis(v_t, U_k^(t), tau^(t))online. - Fine-Grained MoE Sink-Expert Wrapper & Vectorized 3D INT4 Triton Engine (
64&128Experts): WrapsOLMoE,Qwen3-MoE,Qwen2-MoE, andMixtralSparseMoeBlocklayers acrosstransformers 4.xand5.x, profiles layerwise Expert-Exploit Mutual InformationI(Expert; Hack), and includesPackedInt4MoEExperts+load_quantized_3d_moe_causal_lmwith an explicit@triton.jitin-placeINT4-dequantGEMVkernel (0 MBtransient weight writes,11.4xfaster full-model30.5Bevals) so30.5B128-expert MoEs train on a single24 GB - 40 GBGPU.
Installation
pip install sinkroute
# With Hugging Face TRL & PEFT integration:
pip install "sinkroute[trl]"
Quickstart
1. Wrapping Hugging Face TRL GRPOTrainer
from sinkroute import MetamorphicCanary, SinkRouteConfig, attach_sinkroute, wrap_trl_grpo_trainer
config = SinkRouteConfig(
mode="auto", # Automatically injects Dual-LoRA (dense) + MoESinkWrapper (MoE)
depth_fraction=0.571, # Mid-network commitment layer (e.g. Layer 21/36 or 27/48)
subspace_rank=8,
lora_rank=16,
num_sink_experts=2,
token_level_routing=True, # Causal token-window gate w_(b, t)
canary_rate=0.12, # Sparse 12% metamorphic audit rate
co_evolve_every=6,
)
router = attach_sinkroute(model, config)
router.calibrate(H_calibration_pooled, y_calibration_hack_labels)
trainer = wrap_trl_grpo_trainer(
grpo_trainer,
router,
canary=MetamorphicCanary(canary_rate=0.12),
)
trainer.train()
# Export clean LoRA_main / main_adapter weights (Sink weights stripped automatically):
router.save_pretrained("./clean_checkpoint", include_sink=False)
2. Custom PyTorch GRPO Loop (Compatible With Gradient Checkpointing)
w_tok, H_pool, did_evolve = router.compute_routing_weights(
seq_ids,
attention_mask,
prompt_lens,
proxy_rewards,
canary_labels=audited_labels, # {rollout_idx: 0 (honest) or 1 (hack)}
)
# Keep routing_context active across BOTH forward and backward passes:
with router.routing_context(w_tok):
logits = model(input_ids=seq_ids, attention_mask=attention_mask).logits
loss = compute_grpo_loss(logits, seq_ids, advantages)
loss.backward()
optimizer.step()
3. Single-GPU 30B 128-Expert MoE Streaming INT4 Loader (transformers >= 5.0)
Standard bitsandbytes load_in_4bit=True skips fused 3D nn.Parameter expert tensors (OlmoeExperts, Qwen3MoeExperts) in transformers >= 5.0. sinkroute includes a native streaming group-64 INT4 3D MoE loader with Triton-fused unique-expert unpacking:
import torch
from sinkroute import SinkRouteConfig, attach_sinkroute, load_quantized_3d_moe_causal_lm
model = load_quantized_3d_moe_causal_lm(
"Qwen/Qwen3-30B-A3B-Instruct-2507",
device="cuda",
dtype=torch.bfloat16,
group_size=64,
)
router = attach_sinkroute(model, SinkRouteConfig(mode="auto", num_sink_experts=2))
4. Profiling Layerwise Expert-Exploit Mutual Information I(Expert; Hack)
from sinkroute import apply_native_expert_quarantine, profile_moe_exploit_localization
loc_profile = profile_moe_exploit_localization(
router.model,
cal_input_ids,
cal_attention_mask,
cal_prompt_lens,
cal_y_hack,
n_permutations=64,
)
print(f"Peak SNR over 99th-pct null: {loc_profile['peak_snr_over_null']:.2f}x")
Empirical Scaling & Fine-Grained MoE Summary
Evaluated on the 280-task dual-oracle SWE-Loophole-RLVR Python algorithmic suite (6 ID DP/graph families, 2 strictly disjoint OOD families, 4 realistic CI harness loopholes, and 40 zero-loophole clean_controls):
A. Dense Scaling Ladder (Qwen2.5-Coder 1.5B -> 3B -> 7B, 36 GRPO Steps)
Model (57.1% Layer) |
Step=0 CV AUROC (Explicit / Silent CoT) | Unmonitored Peak TrueSolve |
Static Dual-LoRA Peak TrueSolve |
Co-Evolving SinkRoute Peak TrueSolve |
Post-RL Subspace Rotation (FreshCV) |
Key Scaling Finding |
|---|---|---|---|---|---|---|
Qwen2.5-Coder-1.5B (L16/28, d=1536) |
1.000 / 1.000 |
4.17% (6 cum solves) |
2.08% (0.0% ID) |
14.58% (20.83% OOD) |
86.0 deg (0.619) |
Token-level w_(b,t) prevents <think> prefix starvation (3.5x over unmonitored, 7.0x over sequence-pooled static Dual-LoRA) |
Qwen2.5-Coder-3B (L21/36, d=2048) |
1.000 / 1.000 |
25.00% (6.25% final hack) |
31.25% (10.42% hack rebound) |
31.25% (2.08% final hack, 82 cum solves) |
88.4 deg (0.815) |
Co-evolution cuts terminal hack rebound -80.0% vs. static Dual-LoRA and -39.4% in cumulative hacks (20 vs. 33) |
Qwen2.5-Coder-7B (L16/28, d=3584) |
1.000 / 1.000 |
50.00% (95 cum solves, 20.8% clean) |
52.08% (114 cum solves, 37.5% clean) |
56.25% (87.5% OOD, 131 cum solves, 41.7% clean) |
88.3 deg (1.000) |
+37.9% cumulative honest solves (131 vs. 95) and 2.0x clean-control coding accuracy; rotation hits 89.6 deg by step=12 (2x faster than 3B) |
B. Fine-Grained MoE Exploit Localization (64 vs. 128 Experts)
| MoE Architecture | Active / Total Params | 57.1% CV AUROC (Explicit / Silent) |
Early vs. Mid-Late Routing JSD (bits) |
Peak Layer SNR Over 99th-Pct Null |
Top Hack-Enriched Expert | MoE Training Outcome |
|---|---|---|---|---|---|---|
OLMoE-1B-7B (16L, 64 experts, top-8) |
1.3B / 6.9B |
1.000 / 1.000 |
0.00297 -> 0.00769 (2.59x mid-late) |
7.32x (L6 6.90x, L9 peak JSD) |
L9 Expert #12 (2.86x enriched) |
Static native quarantine rebounds +33.3% (12 vs. 9 hacks); SinkRoute cuts hacks -50.0% vs. quarantine (6 hacks) |
Qwen3-30B-A3B (48L, 128 experts, top-8) |
3.3B / 30.5B |
1.000 / 1.000 |
0.02466 -> 0.04278 (5.56x stronger than 64E; global peak JSD = 0.0497 bits at L27 = 57.3% depth) |
8.58x (L31, 65.6% depth) |
L27 Expert #93 (8.22x), L34 Expert #47 (10.05x) |
Native quarantine collapses final TrueSolve -50.0% (20.8% -> 10.4%, 26/144 cum solves); SinkRoute lifts cum genuine solves +57.7% over quarantine (41/144, 28.5%, p = 0.0504) and +32.3% over unmonitored (31/144) with 0.0% hacks |
CLI Usage
# Run Dense or MoE GRPO benchmark arms:
sinkroute run-benchmark \
--models qwen2.5-coder-1.5b,qwen2.5-coder-3b,qwen2.5-coder-7b,olmoe-1b-7b,qwen3-30b-a3b \
--arms unmonitored,static_dual_lora,coevolving_sinkroute,native_expert_quarantine \
--steps 36 --eval-every 12 --out-dir results --device cuda
# Render 4-panel scaling & MoE localization figure:
sinkroute plot --results-dir results --out figures/sinkroute_scaling_and_moe.png
Citation
@techreport{gaskins2026sinkroute,
title = {Co-Evolving Subspace Sink Routing Across Dense Scale and Fine-Grained Mixture-of-Experts RLVR Coding Agents},
author = {Gaskins, Daniel},
institution = {Daniel Gaskins Research},
year = {2026},
month = dec,
url = {https://danielgaskins.com/sinkroute.html}
}
Metadata
Release files for sinkroute 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sinkroute-0.1.0.tar.gz | 1.1 MB | With provenance | Details for sinkroute-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sinkroute-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for sinkroute-0.1.0-py3-none-any.whl |
Total release size: 1.1 MB
Release files / sinkroute-0.1.0.tar.gz
| Download URL | sinkroute-0.1.0.tar.gz |
|---|---|
| Size | 1.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ac9393aae5ecc00276de15acee65dbc967dd0128c45f6739fc67c602b7ad95e
|
|
BLAKE2b-256 checksum How to use checksums |
e15cc059c8ec901f20097266898f6752c1430c13a7a3723d7d1c1d34918050b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logRelease files / sinkroute-0.1.0-py3-none-any.whl
| Download URL | sinkroute-0.1.0-py3-none-any.whl |
|---|---|
| Size | 67.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
62bb8da98c0cb88e2af8b12e92039a8939d89758d8f785a7e0df23db17fc6380
|
|
BLAKE2b-256 checksum How to use checksums |
717463d89f6cbed97704a2ff831068445f3afe8207fb755ce4cc3ae5158dbc04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logSecurity for sinkroute 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sinkroute-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.