Skip to content

About

Moving beyond discrete tokens, we introduce continuous vector generation to deliver seamless, ultra-efficient language modeling at scale.

Resources

Stars

7 stars

Watchers

0 watching

Forks

Repository files navigation

Cadence AI

An attributed CALM research fork for continuous vector generation and adaptive token-patch experiments.

Python 3.10+ License: MIT PyTorch 1.13+ Transformers 4.43 Status: Research


Cadence AI Hero

Overview

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.

System Architecture

Cadence AI is a two-stage system:

  1. Autoencoder: Compresses K tokens into a continuous latent vector and reconstructs them.
  2. Continuous Model: Autoregresses over the latent space using a choice of heads.

Patch-Level Architecture

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.

How It Works

Cadence AI transforms token streams into patch embeddings, predicts a latent vector for the next patch, and decodes that vector back into tokens.

Generation Flow


Training Pipeline

Cadence AI uses a two-stage training pipeline with optional alternative heads and a baseline autoregressive model for comparison.

Training Pipeline


Evaluation

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.

BrierLM Evaluation


Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Prepare Data

bash data/get_data.sh

This downloads and preprocesses pile-uncopyrighted. Plan for ~2.5TB of disk space.

3. Train the Autoencoder

bash train/train_autoencoder.sh

4. Train the Continuous Model (Energy Head)

bash train/train_energy.sh

Optional Heads

bash train/train_diffusion.sh
bash train/train_flow.sh

Optional Baseline (Token-Level)

bash train/train_ar.sh

5. Evaluate

bash train/eval_energy.sh

Inference

Cadence 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))

Configuration Highlights

Autoencoder (configuration_autoencoder.py)

  • patch_size, latent_size, hidden_size
  • num_encoder_layers, num_decoder_layers
  • ae_dropout, kl_weight, kl_clamp

Cadence (configuration_cadence.py)

  • ae_path, model_type
  • patch_size, latent_size, hidden_size
  • num_mlp_layers, num_samples, noise_size
  • num_hidden_layers, num_attention_heads, num_key_value_heads

Cadence experimental features

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.


Repository Structure

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 & Support

  • 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.

Contributing

Contributions are welcome. If you plan a large change, open an issue first so we can align on scope.


License

MIT. See LICENSE for details.


Made with care by divyamtalwar.

Cadence-AI

About

Moving beyond discrete tokens, we introduce continuous vector generation to deliver seamless, ultra-efficient language modeling at scale.

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages