One query per effective sublayer: what it costs, what it fixes

2.2. One query per effective sublayer: what it costs, what it fixes#

ARLoop’s loop is weight-tied only in its transformer blocks: the routing is indexed by effective depth. This page counts the routing parameters from the configuration files of the released checkpoints (stored in book/data/hf/, pinned by revision and SHA-256) and checks the counts against the parameter totals reported by the Hugging Face API.

Hide code cell source

rows = []
for name, ck in lib.CHECKPOINTS.items():
    cfg = lib.config(name)   # checks the SHA-256 of the stored file
    rows.append((name, f"`{ck['repo']}`", f"`{ck['revision'][:8]}`", f"{ck['parameters']:,}", f"`{ck['config_sha256'][:12]}…`"))
lib.md(lib.table(rows, ["model", "repository", "revision", "parameters (HF API)", "config.json SHA-256"]))

model

repository

revision

parameters (HF API)

config.json SHA-256

ARLoop-0.6B

osunlp/ARLoop-0.6B

5cd28f3d

583,138,944

d4de7ddcfc27…

PreNormLoop-0.6B

osunlp/PreNormLoop-0.6B

e4ad59d0

582,804,096

1e0b2e41b5ca…

ARLoop-1.2B

osunlp/ARLoop-1.2B

a29f310a

1,208,655,360

b442805d4d13…

2.2.1. The 0.6B pair#

Hide code cell source

c06 = lib.config("ARLoop-0.6B")
vec = lib.routing_vectors(c06)
r06 = lib.routing_parameters(c06)
gap = lib.CHECKPOINTS["ARLoop-0.6B"]["parameters"] - lib.CHECKPOINTS["PreNormLoop-0.6B"]["parameters"]
print("effective sublayers 2 × physical_layers × loop_count =", lib.effective_sublayers(c06))
print("routing vectors:", " + ".join(f"{v} {k}" for k, v in vec.items()), "=", sum(vec.values()))
print(f"routing parameters: {sum(vec.values())} × hidden_size {c06['hidden_size']:,} = {r06:,}")
print(f"parameter gap ARLoop-0.6B − PreNormLoop-0.6B (HF API): {gap:,}")
effective sublayers 2 × physical_layers × loop_count = 108
routing vectors: 108 queries + 108 norms + 1 final query + 1 final norm = 218
routing parameters: 218 × hidden_size 1,536 = 334,848
parameter gap ARLoop-0.6B − PreNormLoop-0.6B (HF API): 334,848

The 108 effective sublayers of ARLoop-0.6B each carry a query and an RMSNorm weight, and the read-out carries one more of each: \(218 \times 1536 = 334{,}848\) routing parameters. This is exactly the difference between the parameter counts of ARLoop-0.6B and PreNormLoop-0.6B: the pair differs in the routing and in nothing else that has parameters. [code + num]

The whole count follows from the configuration. With the module list of the released modeling code (tied embedding, one shared value embedding, per layer the attention projections, the SwiGLU matrices, two norms, and a value-embedding gate in every second layer; Q/K normalisation without parameters; seminar_lib.backbone_parameters), the three totals are reproduced to the last parameter:

Hide code cell source

rows, exact = [], []
for name, ck in lib.CHECKPOINTS.items():
    cfg = lib.config(name)
    parts = lib.backbone_parameters(cfg)
    routing = lib.routing_parameters(cfg) if "sw_blocks" in cfg else 0
    total = sum(parts.values()) + routing
    exact.append(total == ck["parameters"])
    rows.append((name, f"{sum(parts.values()):,}", f"{routing:,}", f"{total:,}", f"{ck['parameters']:,}",
                 "exact" if total == ck["parameters"] else "**differs**"))
lib.md(lib.table(rows, ["model", "backbone (from config)", "routing", "total", "HF API", "match"]))

model

backbone (from config)

routing

total

HF API

match

ARLoop-0.6B

582,804,096

334,848

583,138,944

583,138,944

exact

PreNormLoop-0.6B

582,804,096

0

582,804,096

582,804,096

exact

ARLoop-1.2B

1,208,061,440

593,920

1,208,655,360

1,208,655,360

exact

2.2.2. ARLoop-1.2B#

Hide code cell source

c12 = lib.config("ARLoop-1.2B")
r12 = lib.routing_parameters(c12)
v12 = sum(lib.routing_vectors(c12).values())
share06 = r06 / lib.CHECKPOINTS["ARLoop-0.6B"]["parameters"]
share12 = r12 / lib.CHECKPOINTS["ARLoop-1.2B"]["parameters"]
print(f"ARLoop-1.2B: {lib.effective_sublayers(c12)} effective sublayers")
print(f"    routing parameters {v12} × {c12['hidden_size']:,} = {r12:,}")
print(f"share of the model: ARLoop-0.6B {100 * share06:.3f}%, ARLoop-1.2B {100 * share12:.3f}%")
ARLoop-1.2B: 144 effective sublayers
    routing parameters 290 × 2,048 = 593,920
share of the model: ARLoop-0.6B 0.057%, ARLoop-1.2B 0.049%

ARLoop-1.2B has 144 effective sublayers and \(290 \times 2048 = 593{,}920\) routing parameters. In both models the routing is about 0.05% of the parameters (0.057% and 0.049%). [code + num]

2.2.3. One effective vector per sublayer#

In the score \(q_i^\top\operatorname{Norm}(z_j)\) the RMSNorm weight \(g_i\) multiplies the query coordinate-wise, so only \(q_i \odot g_i\) matters: one effective routing vector per routing call [code]. The vector of call 0 is inert (finding F8; The window, block by block).

Hide code cell source

eff = (lib.effective_sublayers(c06) + 1) * c06["hidden_size"]
print(f"effective routing vectors of ARLoop-0.6B: {lib.effective_sublayers(c06) + 1}")
print(f"    {eff:,} effective parameters, of which {c06['hidden_size']:,} (call 0) cannot act")
effective routing vectors of ARLoop-0.6B: 109
    167,424 effective parameters, of which 1,536 (call 0) cannot act

2.2.4. More loops than trained#

PreNormLoop has no depth-indexed parameters, so it runs at any number of loops. ARLoop-0.6B has routing parameters (a query and a norm weight) for 108 sublayers and none for a fourth loop: running it at \(R > 3\) needs a rule for the missing ones (finding F1 of the digest). The paper’s App. D.2 initialises new queries for the unseen depths and trains them with the rest of the model frozen; E1 instead declares two inference-only rules (experiments/e1_release/loopctl.py), and E3 adds a trainable bank for loop 4.

Hide code cell source

trained = c06["loop_count"]
rows = [(k, lib.query_rule(k, trained, "repeat"), lib.query_rule(k, trained, "cycle")) for k in range(1, 7)]
lib.md(lib.table(rows, ["loop", "routing reused under `repeat`", "routing reused under `cycle`"]))
bank = 2 * c06["physical_layers"] * c06["hidden_size"]
print(f"E3's loop-4 bank: {2 * c06['physical_layers']} queries + {2 * c06['physical_layers']} norm weights")
print(f"    = {2 * 2 * c06['physical_layers']} vectors = {2 * bank:,} parameters")

loop

routing reused under repeat

routing reused under cycle

1

1

1

2

2

2

3

3

3

4

3

1

5

3

2

6

3

3

E3's loop-4 bank: 36 queries + 36 norm weights
    = 72 vectors = 110,592 parameters

Under repeat, loops 4, 5 and 6 reuse the queries and norm weights of loop 3; under cycle, loop 4 reuses loop 1’s, loop 5 loop 2’s and loop 6 loop 3’s. E3’s bank for a fourth loop has 36 queries and 36 norm weights (110,592 parameters), initialised as copies of loop 3’s and trained only in the random-depth arm. Whether any of this helps is an experimental question (see E1, E3 and Stage 1c). [num]