code-switch-mtp / docs /experiment-log.md
Anupam-Rawat-IITB's picture
Add code, result files and documentation
3bbd5dd verified
|
Raw History Blame Contribute Delete
23.7 kB

Experiment log

2026-08-29 -- Phase 0: hardware sanity

Ran scripts/phase0_sanity_check.py. All four GPUs report capability (6, 1); sm_61 is absent from torch.cuda.get_arch_list() but kernels run correctly via PTX JIT from sm_60 (see docs/hardware-notes.md). Llama-3.2-1B fp32 forward pass: 4769 MiB peak, ~28 ms/iter on GPU 0. Training step (frozen backbone + 1 MTP head, batch 4 x seq 512): ~2500 tokens/sec, meaningfully faster than the brief's ~3 TFLOP/s/card planning assumption. No blockers.

2026-08-29 -- Phase 1: data pipeline, HALTED at reversibility check

Ran scripts/phase1_data_pipeline.py.

Step 1 (Hindi corpus) completed cleanly: streamed ai4bharat/sangraha verified/hin, 119,542 docs seen, 117,517 kept (2,019 duplicates dropped, 6 too-short dropped), 50,000,203 tokens, written to /data/cs769_mtp/scratch/data/hindi_corpus/sangraha_hin_50M.jsonl. Took ~35 seconds -- a prior small-sample extrapolation had projected ~60 minutes; that estimate was dominated by connection startup latency, not steady-state throughput. Actual full run is the only number to trust going forward.

Step 2 (ITRANS reversibility) -- FAILED the brief's own gate. 1000 sentences sampled from Dakshina's hi/romanized/hi.romanized.rejoined.tsv (seed 0), each romanized via extended ITRANS (indicnlp.transliterate.unicode_transliterate.ItransTransliterator) and de-romanized back. Exact-match rate: 0.659 (659/1000), against a 0.99 threshold. Per the brief, this is a hard stop: "a lossy L2 invalidates the design." Pipeline halted before steps 3-4 (Dakshina triples, ambiguity histogram); neither ran.

Follow-up diagnosis (not part of the committed pipeline, run interactively to characterize the failure): normalizing away three specifically "cosmetic" difference classes on both sides before comparing -- (a) nukta consonants stripped (ज़/ड़/फ़ etc. collapsed to their base consonant), (b) digit script unified (Latin 18 vs Devanagari १८), (c) terminal punctuation unified (ASCII '.' vs Devanagari danda '।') -- raises the match rate only to 0.778. The remaining ~22% of sentences fail for structural reasons intrinsic to this library's ITRANS scheme, not formatting, e.g.:

  • independent-vs-dependent-vowel ambiguity: गई ("gai") comes back as गैइ, not गई -- the library's own code comments acknowledge this ambiguity class but do not resolve it losslessly.
  • ITRANS string-level collisions: "ld" is a registered alternate spelling for the independent character ळ (retroflex la) and the literal transliteration of ल्द् (la + halant + da); हल्द्वानी round-trips to हळ्वानी because the de-romanizer cannot tell which was meant.

Nukta loss alone (root cause of the largest single class of failures, e.g. बाज़ार -> baajaaara -> बाजाअर) is expected given how common nukta consonants are in real Hindi text (Persian/Arabic loanwords); it was already visible in a 3-sentence manual spot-check before the formal test ran (see prior session). The vowel-sign/conjunct ambiguity classes were not anticipated and are the more serious finding: they mean extended ITRANS via indic-nlp-library is not a lossless transform in general, which is a problem for the study's premise that L2 has "identical morphology and content" to L1, not just a data-cleanliness issue to route around.

Not resolved. Waiting on a decision before Phase 1 steps 3-4 or any later phase: see chat for options under consideration (alternative transliteration tooling, filtering Dakshina to only exactly-reversible sentences, or accepting a documented information loss and adjusting what L2 is claimed to hold constant).

2026-08-29 -- Phase 1 continued: reversibility fixed, pipeline complete

Decision taken: switch transliteration backend to aksharamukha (adds the dependency; drops indic-nlp-library, which is no longer used anywhere in the codebase) and route embedded Latin-script spans (English words, acronyms -- common in Wikipedia-sourced Hindi) around conversion instead of feeding them through it, plus a normalize_for_comparison step that treats digit script (Latin vs Devanagari digits), NFC form, and sentence-final punctuation variants (., danda ।, double danda ॥, and a bare | this corpus uses as an old danda stand-in) as equivalent before comparing -- these are the same content differently rendered, not a loosened bar. See src/data/itrans_transliterate.py for the reasoning behind each step, including why deromanize() cannot safely protect embedded Latin spans the way romanize() does (ITRANS is itself Latin-alphabet, so a plain Latin-run split on it matches the whole string) and uses an internal marker-based path instead for reversibility checking specifically.

Reversibility on the same 1000-sentence sample (seed 0): 0.990 (990/1000), up from 0.659, clearing the 0.99 threshold. Remaining failures are a mix of a few further vowel-sign edge cases (अा vs आ) and one or two genuinely unusual inputs (a mis-typed word with stray matras); none showed the systematic pattern the indic-nlp-library failures had.

Filtered the full 10,000-row Dakshina pool (not just the sample) through the same check: 9,908 of the 10,000 rows are unique sentences (92 rows are exact duplicates of another row's Devanagari text -- a property of the source data, not of this pipeline); of those, 9,815 unique sentences pass, yielding 9,907 fertility triples (row-level, so passing duplicate rows are each kept) written to results/phase1_fertility_triples.csv.

Step 4 (romanization ambiguity from the Dakshina lexicon) is independent of the sentence-level reversibility question -- it reads Dakshina's own human-annotated lexicon directly, not anything produced by this pipeline's transliteration -- so it was not filtered by the reversible subset: 30,000 native types, mean 1.7688 attested romanizations per type, histogram in results/phase1_romanization_ambiguity.csv.

Full pipeline (python scripts/phase1_data_pipeline.py) now runs end-to-end in ~1m20s. Phase 1 is complete.

2026-08-29 -- Phase 2: zero-training measurement, complete

Models: Sarvam-1 (L1), Llama-3.2-1B (L2-L4, E1), ByT5-large (L5, E2). ByT5 ships only as a pickle .bin checkpoint, which current transformers refuses to torch.load below torch 2.6 (a CVE guard); rather than touch the torch==2.5.1+cu121 pin (load-bearing for sm_61 PTX support), the checkpoint was converted to safetensors locally via torch.load(..., weights_only=True) -- a safe, standard remediation, not a bypass -- and is loaded from /data/cs769_mtp/scratch/models/byt5-large-safetensors. ByT5 is encoder-decoder, not causal decoder-only like the other two models; src/measure/model_handle.py drives it by mirroring the growing sequence into both encoder and decoder input (a standard T5-family scoring trick), which gives it bidirectional encoder access to the prefix a causal model only sees causally. This is a real architecture mismatch for L5/E2 vs L1-L4, documented here rather than treated as equivalent -- keep it in mind interpreting any L5/E2 comparison.

Scope reduction, decided and logged, not silent: a timing calibration (5 sentences, max_positions=3, M=8 Monte Carlo samples) measured ~7s/sentence on this hardware, because the entropy/D_indep estimators have no KV-caching -- every Monte Carlo rollout step re-runs the full prefix from scratch. At that rate the full 9,907-sentence pool would run multiple hours per condition. Ran 100 sentences/condition (random sample, seed 0) with max_positions_per_sentence=5, max_horizon=8, M=8 instead. All 7 conditions ran as genuinely concurrent GPU-pinned processes (verified via matched start timestamps in phase2_out/concurrency.log and nvidia-smi showing 91-100% utilization on all four GPUs simultaneously), completing in ~33.5 minutes wall-clock (08:04:19-08:37:47). This is a directional, higher-variance measurement appropriate to a Stage 1 PoC, not a publication-grade final number -- rerunning on the full pool with proper KV-caching is the natural next step before this feeds a paper.

Sanity checks against earlier interactive findings: fertility reproduced closely -- L1 1.74 (vs 1.61 on the full 9,907-sentence pool), L5 14.74 (vs 14.34), consistent given this run's 100-sentence resample. E1 (English subword) 1.50, E2 (English byte) 6.26 -- both close to the brief's 1.3/5 expectations. No negative KL values anywhere in results/phase2_measurements.csv (would indicate an estimator bug); none occurred.

Entropy trough depth -- does NOT separate L1 from L5 most sharply, contrary to the brief's expectation. Measured (mean intra-word entropy / mean boundary entropy, horizon=1 only): L1=0.790, L2=0.918, L3=0.832, L4=0.700, L5=0.809. L1 and L5 are close (0.790 vs 0.809); L4 is actually the most different from L1 (0.700). This is a real, reportable deviation from the brief's prediction, not a bug -- worth investigating further (possibly confounded by the L5/ByT5 architecture mismatch noted above) rather than assumed to resolve itself at full scale.

D_indep -- a genuinely on-target result. The byte-level conditions show markedly lower D_indep (KL from the true joint to the product-of-independent-marginals) than every subword condition, at both k=2 and k=3:

condition d_indep_k2 d_indep_k3
L1 (Devanagari+Sarvam) 2.49 10.01
L2 (ITRANS+Llama) 2.60 8.89
L3 (natural-roman+Llama) 2.70 9.49
L4 (Devanagari+Llama) 2.84 8.92
L5 (Devanagari+byte) 0.41 2.94
E1 (English subword) 2.84 10.81
E2 (English byte) 0.34 1.01

Byte-level spans are far closer to independent than subword spans, for both languages -- directly consistent with Gloeckle et al. and Aynetdinov & Akbik's finding that MTP helps more at byte granularity: there is simply less joint structure for independent per-head prediction to lose. This is the clearest signal in this phase's results and the one most worth carrying into Phase 3's actual training comparison, modulo the L5/ByT5 architecture caveat above (E2 is the more trustworthy of the two byte-condition numbers to lean on if that caveat matters, since a byte-level English baseline is less central to H1 than the Hindi L1-vs-L5 contrast is, but both point the same direction here).

Boundary alignment fraction is much lower for byte conditions (L5=0.14, E2=0.32) than subword conditions (0.32-0.73) -- expected and not a bug: with far higher fertility, the many within-word byte-to-byte boundaries dilute the fixed count of true word-boundary positions, even though every whitespace character is itself still a clean single-byte token.

Full results in results/phase2_measurements.csv (182 rows, one per condition x metric). Phase 2 (100-sentence-per-condition PoC scope) is complete.

2026-08-29 -- Phase 2b: blocker resolution, two Phase 2 findings corrected

Two blockers were opened against Phase 2 before Phase 3's design could be settled. Both are now resolved, and both overturn a conclusion recorded in the Phase 2 entry above. Raw numbers in results/phase2b_blockers.csv.

Blocker A -- the L1 D_indep anomaly is mostly a MODEL artifact

Phase 2 found L1 had the lowest fertility (1.74) yet the highest d_indep_k3 (10.01), which read as evidence against a purely fertility-driven account. But L1 was also the only condition on Sarvam-1; model identity and script were confounded. A 2x2 factorial (n=2000/cell, same paired sentence subset across all cells) separates them:

cell fertility d_indep_k2 d_indep_k3 k3 stderr
Sarvam-1 x Devanagari 1.728 2.409 9.735 0.079
Sarvam-1 x ITRANS-roman 3.681 2.867 9.558 0.060
Llama-3.2-1B x Devanagari 3.051 2.877 8.665 0.056
Llama-3.2-1B x ITRANS-roman 3.065 2.614 8.925 0.062

Decomposition at k=3: model main effect (Sarvam - Llama) = +0.851; script main effect = -0.041; interaction = +0.437. The model effect holds in both script conditions as a within-sentence paired difference: +1.059 +/- 0.098 on Devanagari (10.9 sigma), +0.632 +/- 0.086 on Roman (7.4 sigma).

Interpretation. Sarvam-1 shows systematically higher D_indep than Llama-3.2-1B irrespective of script, so Phase 2's L1 anomaly is principally a model-identity artifact, not a morphology signal. This is a negative result for cross-model comparability along the fertility ladder: any L1-vs-L2/L3/L4 contrast carries a model effect roughly twice the size of the script effect.

A second, independent observation from the same table matters at least as much: fertility does not drive D_indep within either model. Within Sarvam-1 fertility more than doubles (1.73 -> 3.68) while d_indep_k3 barely moves (9.74 -> 9.56, i.e. slightly down); within Llama-3.2-1B fertility is flat (3.05 vs 3.07) and d_indep_k3 is likewise flat (8.67 vs 8.93). Over the subword fertility range accessible here, D_indep tracks which model is being used, not how fertile its tokenizer is. H1's premise -- that fertility is the mechanism -- is not supported by the subword conditions; the byte-vs-subword gap from Phase 2 remains the one place a large D_indep difference actually appears.

Blocker B -- the trough-depth "failure" was a sampling bug, not architecture

Phase 2 reported that entropy trough depth did not separate L1 from L5 (0.790 vs 0.809), contrary to the brief's prediction, and attributed this tentatively to the ByT5 encoder-decoder mismatch. That attribution was wrong, and the underlying number was invalid.

compute_entropy_profile sampled the FIRST max_positions token positions of each sentence. Devanagari characters are 3 bytes in UTF-8, so under byte-level tokenization the first word boundary falls around byte 11-12 -- never inside the first 5 sampled positions. The byte conditions therefore had n_h1_boundary at or near 0 and a degenerate (often NaN) trough depth computed off a tiny biased subset. Fixed in 954e0c2 by adding an evenly-spaced position strategy, with the leading strategy retained so Phase 2's committed numbers stay reproducible, and a regression test in 212974f.

Driving mode turns out to be nearly irrelevant once sampling is fixed; position strategy dominates:

ByT5 driving mode leading positions spread positions
mirrored (bidirectional encoder) 0.752 1.129
causal decoder-only 2.141 1.212

Corrected trough depths, all seven conditions (spread sampling, horizon 1, n=400 sentences/condition):

condition Phase 2 (buggy) corrected n_points
L1 Devanagari+Sarvam 0.790 0.621 1883
L2 ITRANS+Llama 0.918 0.878 1971
L3 natural-roman+Llama 0.832 0.782 1927
L4 Devanagari+Llama 0.700 0.699 1973
L5 Devanagari+byte 0.809 1.065 2000
E1 English+Llama 0.688 0.647 1990
E2 English+byte 0.911 0.873 2000

Interpretation. With the bug fixed, the brief's original prediction holds after all: L1 (0.621) and L5 (1.065) are now the two extremes of the Hindi ladder, a clear separation rather than the near-identical pair Phase 2 reported. The subword conditions move only slightly under the fix; L5 moves most, exactly as the byte-length argument predicts. The Phase 2 entry's claim that trough depth "does NOT separate L1 from L5" is retracted.

Status of Phase 2's committed numbers

results/phase2_measurements.csv retains its original entropy_trough_depth rows, which were produced with leading-position sampling. They are superseded for all seven conditions by the entropy_trough_depth_spread_corrected rows in results/phase2b_blockers.csv; prefer the latter. The other Phase 2 metrics (fertility, boundary alignment, D_indep, AdaMTP) are unaffected by this bug, and D_indep specifically is now corroborated at n=2000 by Blocker A's Llama cells (k=3 8.665/8.925 vs Phase 2's 100-sentence 8.665-8.925 range).

2026-08-29 -- Phase 3: MTP head training, single backbone

Three conditions on one frozen Llama-3.2-1B backbone: L4 (Devanagari), L2 (ITRANS romanization of the same sangraha documents), E1 (English Wikipedia). 10M training tokens each, batch 2 x seq 512, AdamW at 1e-4, seed 0, run concurrently one per GPU. Raw rows in results/phase3_training.csv and results/phase3_measurements.csv.

Single backbone, by design. Phase 2b measured the model-identity effect on D_indep at +0.851 (k=3, 10.9 sigma) against a script effect of -0.041, so putting L1 on Sarvam-1 alongside Llama conditions would have confounded the primary comparison with a term twice the size of the effect under study. One backbone removes it outright. The cost is a narrow fertility range (L2 3.07, L4 3.05, E1 1.50), which is stated up front rather than presented as a ladder it is not.

L3 is absent and cannot be added. Human-written romanization exists only in Dakshina's 9,907 sentences, roughly 0.38M tokens against a 10M budget. Machine romanization is not a substitute: H3 concerns human orthographic variation specifically, so a synthetic stand-in would test nothing. H3 is untestable at training scale with available data, and no amount of compute changes that -- it is a data limitation.

The specified architecture cannot measure D, and this was verified

The brief's Phase 3 architecture is a frozen backbone with 4 x [ResBlock -> shared unembedding]. Under it, head 1's parameters appear in exactly one loss term, so its gradients are bit-identical to a standalone next-token head's; the k=2..4 objectives cannot reach them. D = BPB(MTP) - BPB(NTP) is therefore zero by construction, whatever the data and however long training runs. Confirmed twice: analytically (gradient equality, max abs difference 0.0) and empirically -- an ablation run trained 900 steps on L4 with no shared trunk returned BPB mtp=0.491096 ntp=0.491096 D=0.000000, identical to six decimals, with the training losses equal at every logged step.

The brief's own framing of multi-token prediction is "a shared trunk with k parallel heads", and the cost the literature reports comes from that trunk serving k objectives at once. With the backbone frozen, the only trunk available is a trainable adapter between it and the heads, so that is what the primary runs use: frozen backbone -> trainable shared ResBlock -> 4 per-head ResBlocks -> shared frozen unembedding. The NTP control gets its own trunk and head, sharing no trainable tensor with the MTP stack (asserted in tests/test_train.py). The trunkless variant stays available behind --no-shared-trunk.

Results

condition BPB(MTP) BPB(NTP) D D relative accepted/forward boundary completion
L4 Devanagari 0.486695 0.482983 0.003712 0.77% 2.655 0.299
L2 ITRANS-roman 1.782721 1.760392 0.022329 1.27% 2.359 0.301
E1 English 0.709532 0.694181 0.015351 2.21% 2.222 0.716
L4 no shared trunk 0.491096 0.491096 0.000000 0.00% 2.485 0.315

D is positive in every shared-trunk condition: adding the t+2..t+4 objectives does measurably degrade t+1 quality, which is the cost the multi-token-prediction literature reports, reproduced here at 1B scale on a frozen backbone.

Absolute BPB is not comparable across these conditions. L2 and L4 encode identical content, yet their BPB differs roughly fourfold, because Devanagari occupies three UTF-8 bytes per character against one for its romanization -- the same information spread over a third as many bytes raises every per-byte quantity. Only within-condition differences and ratios survive that; d_trained_relative divides it out.

Does the zero-training proxy predict the trained cost?

ordering result
by D_indep (k=3), zero-training L4 < L2 < E1
by D absolute, trained L4 < E1 < L2 -- disagrees
by D relative, trained L4 < L2 < E1 -- agrees

The proxy's ordering is reproduced exactly by relative D and violated by absolute D. Given the byte-density argument above, relative D is the better-posed cross-condition quantity, which favours the proxy. But n = 3 conditions cannot establish this. Three items admit six orderings, so a match carries a 1-in-6 chance of arising at random; this is a single consistent observation, not evidence of a relationship, and no correlation or regression should be quoted from it. Distinguishing "the proxy works on the right scale" from "two of three conditions happened to line up" needs more conditions, which the single-backbone design deliberately traded away.

Per-head accuracy and the boundary metrics

Accuracy falls off sharply with prediction distance in every condition (L4: 0.603, 0.340, 0.204, 0.131 for heads 1-4), and intra-word targets are consistently easier than word-initial ones -- L4 head 1 scores 0.726 intra-word against 0.405 at boundaries. Continuing a word in progress is substantially more predictable than choosing the next one, and that gap is the entropy trough of Phase 2 showing up in trained accuracy.

Boundary-completion rate, this project's novel metric, separates the conditions far more sharply than D does: E1 0.716 against L4 0.299 and L2 0.301. The two Hindi conditions agree to within 0.002 despite using different scripts, while matching each other closely on fertility (3.05 vs 3.07) -- and English, at fertility 1.50, is more than twice as high. On these three points the metric tracks fertility, not script, which is the cleanest fertility-linked signal anywhere in this project. The same caveat applies: three conditions, two of which are near-duplicates in fertility.

Status and limitations

Measured throughput 845-860 tok/s per GPU, peak 7.9GB, roughly 3.2 hours of training per condition plus evaluation. Speculative decoding ran on 256 held-out documents with 64-token completions rather than the specified 512 and 128: the draft/verify loop carries no KV cache, so each round re-encodes the whole growing sequence at 15.2 s/document, which would have cost 130 minutes per condition against 3 hours of training. Acceptance and boundary completion are per-round statistics and the reduced subset still yields 5,600-7,000 scored spans per condition, so precision is not the binding constraint. Held-out documents are disjoint from training by construction and this was verified directly.

Seed variability, and what it does to the ordering

A second seed was run for L4 only, on the GPU the ablation freed:

L4 D D relative accepted/forward boundary completion
seed 0 0.003712 0.00769 2.655 0.299
seed 1 0.003040 0.00629 2.693 0.306

D moves by 0.000672 between seeds, 19.9% of its own mean -- large in relative terms, and a caution against reading small D differences as real. The downstream metrics are far steadier (accepted/forward within 0.04, boundary completion within 0.007).

It does not overturn the ordering: L4's relative D spans [0.0063, 0.0077] across seeds and does not reach L2's 0.0127, and the L2-to-E1 gap (0.0127 to 0.0221) is wider still than that spread. But L2 and E1 were each run once, so their own seed variability is unmeasured and this is an extrapolation from the one condition that has it. Two of three conditions are single-seed, below the two-seed minimum the brief sets for reported numbers, and closing that is the first thing to do before any of these numbers are quoted.