An attributed CALM research fork for continuous vector generation and adaptive token-patch experiments.
Cadence AI is an experimental derivative of CALM. It studies continuous vector generation over K-token patches: an autoencoder compresses patches into latent vectors and an autoregressive model predicts the next vector. The inherited baseline reduces the number of autoregressive decisions; end-to-end throughput improvements still need to be measured for Cadence configurations.
Important
This repository is research code, not an independently validated model release. No Cadence checkpoint or quantitative result is published yet. See UPSTREAM.md for inherited components and the evidence required for future claims.
Research hypotheses
- Fewer steps: Predict K tokens per autoregressive step.
- Scalable bandwidth: Test whether larger or adaptive patches improve semantic throughput.
- Likelihood-free training: Energy, diffusion, and flow heads in latent space.
Cadence AI is a two-stage system:
- Autoencoder: Compresses K tokens into a continuous latent vector and reconstructs them.
- Continuous Model: Autoregresses over the latent space using a choice of heads.
Heads Included
- Energy head: MLP-based generator with energy score objective.
- Diffusion head: Noise-to-latent generation with diffusion loss.
- Flow head: Flow matching in latent space.
Cadence AI transforms token streams into patch embeddings, predicts a latent vector for the next patch, and decodes that vector back into tokens.
Cadence AI uses a two-stage training pipeline with optional alternative heads and a baseline autoregressive model for comparison.
Evaluation uses BrierLM with two latent samples decoded into tokens to assess calibration and consistency without explicit token likelihoods.
Published results should include the raw BrierLM output, autoencoder reconstruction, generation throughput, total sampling cost, exact configuration, upstream/Cadence commits, seeds, and hardware.
pip install -r requirements.txtbash data/get_data.shThis downloads and preprocesses pile-uncopyrighted. Plan for ~2.5TB of disk space.
bash train/train_autoencoder.shbash train/train_energy.shbash train/train_diffusion.sh
bash train/train_flow.shbash train/train_ar.shbash train/eval_energy.shCadence uses a custom generation loop that operates in latent space and decodes patches to tokens.
For temperatures below 1, decoded patch candidates are counted and sampled on the active device with models.patch_sampling.select_modal_patches; the generation path no longer transfers every candidate to Python tuples/Counter. Run python benchmarks/patch_selection.py --device cuda to capture a before/after-compatible microbenchmark receipt.
import torch
from transformers import AutoTokenizer
from models.configuration_cadence import CadenceConfig
from models.modeling_energy import EnergyTransformer
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("llama3_tokenizer")
config = CadenceConfig(
ae_path="/path/to/autoencoder",
patch_size=4,
latent_size=128,
hidden_size=1024,
num_hidden_layers=16,
num_attention_heads=16,
num_key_value_heads=16,
)
model = EnergyTransformer(config).cuda().eval()
prompt = "Write a short paragraph about continuous vector generation."
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.cuda()
output_ids = model.generate(input_ids, max_length=256, temperature=0.5)
print(tokenizer.decode(output_ids[0], skip_special_tokens=True))patch_size,latent_size,hidden_sizenum_encoder_layers,num_decoder_layersae_dropout,kl_weight,kl_clamp
ae_path,model_typepatch_size,latent_size,hidden_sizenum_mlp_layers,num_samples,noise_sizenum_hidden_layers,num_attention_heads,num_key_value_heads
The models/adaptive_patching.py module is the first explicitly Cadence-specific research surface:
- Adaptive patch length maps boundary entropy to 1/2/4/8-token patches, allocating narrower patches to uncertain regions.
- Uncertainty-aware refinement emits accept, resample, or split decisions under explicit thresholds.
- Cross-granularity consistency distills token-level teacher probabilities into decoded continuous patches through a temperature-scaled KL objective.
Run python examples/adaptive_patch_policy.py to inspect decisions. These primitives are tested, but their BrierLM/throughput benefit remains an experimental question and must be reported against the attributed fixed-K CALM baseline.
assets/ # Visual assets (SVG/PNG)
data/ # Data download and preprocessing
get_data.sh
process.py
wikitext_document_level-test.json
llama3_tokenizer/ # Tokenizer assets
models/ # Core model code
configuration_autoencoder.py
configuration_cadence.py
modeling_autoencoder.py
modeling_cadence.py
modeling_energy.py
modeling_diffusion.py
modeling_flow.py
diffusion/
train/ # Training and evaluation
train_autoencoder.py
train_cadence.py
train_energy.sh
train_diffusion.sh
train_flow.sh
train_ar.py
train_ar.sh
eval_energy.sh
requirements.txt
- Docs: This README is the primary reference.
- Issues: Open a GitHub issue for bugs or feature requests.
- Questions: Start a discussion thread if you want design or training guidance.
Contributions are welcome. If you plan a large change, open an issue first so we can align on scope.
MIT. See LICENSE for details.
Made with care by divyamtalwar.