720 GB
6,964 files
Updated 14 days ago
Name
Size
ablations
checkpoints
context_handoff
kvpath
lr_sweep_1b
train_10b_lr_1e-3
README.md5.08 kB
xet
config.toml4.67 kB
xet
test_kvpath.py17.6 kB
xet
train.py521 Bytes
xet
README.md

KVPath-shared

kvpath-shared is a grouped anchor-base + per-layer low-rank-delta attention variant. The Python package, checkpoint model_type="kvpath", and existing configuration field names retain kvpath for compatibility with trained weights. The public benchmark variant is kvpath-shared; the old kvpath variant remains an alias.

This is the portable standalone KVPath bundle, migrated out of DeltaKV so KVPath-shared development/training doesn't mix with DeltaKV's other products (baseline, depth_delta, depth_delta_down, independent_kv, kv_share, ...). It is fully self-contained code-wise: its own env/third_party/Megatron-LM checkout (with the kvpath patches already applied), its own utils/, and a real local dataset/ tree. The portable bundle does not depend on a DeltaKV workspace or a dataset symlink.

Attention

12 layers, cycles of kvpath_group_size (4): layers 0/4/8 are anchors.

  • Every cycle's anchor produces one full-width, RoPE-free base K/V (kvpath_base_head_dim=128 per KV head), cached once and shared by all 4 layers in the cycle.
  • Every layer, including the anchor itself, additionally produces its own rank-kvpath_rank=32 K/V delta, cached per layer. The K delta carries RoPE and is concatenated onto the shared base K (128+32=160-wide K); the V delta is RoPE-free and is concatenated onto the shared base V (128+32=160-wide V).
  • Q is widened to 160 per head: a 128-wide NoPE prefix scores against base K, and a 32-wide RoPE suffix scores against delta K. The RoPE suffix uses its own dim=32 rotary embedding (not a slice of a dim=160 one -- that would sample the wrong, lower-frequency angles), sharing the RoPE theta.
  • No local window, no up-projection, no matrix absorption: attention runs once per layer over the full causal history of the concatenated [base; delta] K/V.
  • scaling = kv_channels**-0.5 = 160**-0.5 (kv_channels=160 already makes this the default for both Megatron's core attention and the HF SDPA path).

Cache footprint: 3 groups * 2 * 4 kv-heads * 128 (base) + 12 layers * 2 * 4 kv-heads * 32 (delta) = 6144 vals/token, independent of context length -- 50% of vanilla 128-dim-head GQA's 12288 vals/token.

Files

  • kvpath/attention.py, kvpath/module_specs.py: Megatron-Core training implementation (training-only; no inference/decode cache -- TP=PP=CP=1).
  • kvpath/configuration_kvpath.py, kvpath/modeling_kvpath.py: HuggingFace side (KVPathConfig, KVPathForCausalLM, KVPathCache), used for evaluation/export and for the prefill-vs-decode correctness test. Attention uses torch.nn.functional.scaled_dot_product_attention exclusively (no hard flash_attn dependency; PyTorch dispatches flash / mem-efficient / math on its own).
  • kvpath/megatron_to_hf.py: weight-key mapping from the (heterogeneous) Megatron checkpoint to the HF state dict. Both sides use fused projections (linear_q_delta↔q_delta_proj, linear_base_kv↔base_kv_proj), so this is a 1:1 key rename with no QKV splitting.
  • config.toml: kv_channels=160, num_query_groups=4, num_attention_heads=8, [model] kvpath_group_size/rank/base_head_dim; otherwise identical to training/baseline/config.toml.
  • test_kvpath.py: single-GPU tests -- parameter-count self-check, group structure, cache-size-vs-context-length, prefill-vs-decode logit parity, forward/backward + overfit sanity, SDPA backend reporting, a Megatron single-GPU training smoke test, and KVPath-shared-vs-GQA parameter parity.

See training/gqa/ for the matched (same cache, same parameter count) GQA baseline: standard Qwen3-style GQA with kv_channels=64, no new Megatron code.

Commands

All commands below assume the current directory is this bundle's root.

source env/activate_deltakv_env.sh   # still the shared 'deltakv' conda env

GPU=$(nvidia-smi --query-gpu=index,memory.used --format=csv,noheader,nounits \
      | sort -t, -k2 -n | head -1 | cut -d, -f1)
export CUDA_VISIBLE_DEVICES=$GPU

# Single-GPU tests (see task section 5).
python training/kvpath/test_kvpath.py
python training/gqa/test_gqa.py

# Architecture-matched random initialization (single GPU regardless of the
# training launcher's nproc_per_node -- init only needs to build the model).
python utils/save_init_checkpoint.py --config training/kvpath/config.toml \
  --nproc-per-node 1 --master-port 6150

# Full training -- defaults to 8-card (config.toml [launcher] nproc_per_node=8).
python training/kvpath/train.py
python training/gqa/train.py

Each model directory (training/kvpath/config.toml, training/gqa/config.toml, and any future model you add under training/<name>/config.toml) is a fully independent config: [optimizer.adamw] lr, [schedule] (warmup/decay/weight_decay), [launcher] (nnodes/nproc_per_node/ports), [data] batch sizes, and [wandb] project/exp_name are all set per-model with no shared/global defaults -- edit one model's config.toml freely without affecting any other model.

Total size
720 GB
Files
6,964
Last updated
Nov 11
Pre-warmed CDN
US EU US EU

Contributors