Language models, retrieval, prompting, and language adaptation · Autoregressive and open-weight model families · LNG039 · Model
DeepSeek-V2 / V3 language-model family
Groups documented sparse language-model designs combining mixture-of-experts computation with efficient attention-state representations.
In CodeSplash
Documented in the Academy only. There's no Set up button.
- Availability
- Explained here
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's own run
- CodeSplash's run
- The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: The chapter's authors report running it; there is no record for this entry alone. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Groups documented sparse language-model designs combining mixture-of-experts computation with efficient attention-state representations. The V3 report also discusses multi-token prediction as a training objective, which should not be confused with guaranteed parallel output generation.
Question / objective
Can sparse experts and compressed attention states improve large language-model efficiency?
Architecture / computational structure
The documented family combines multi-head latent attention, MoE layers, and version-specific training components. Learned latent projections, experts, and routers are parameters; latent ranks, expert counts, and precision strategy are configuration choices.
Assumptions
Compression, routing, and low-precision training have implementation-specific numerical requirements.
Formula / computational definition
Multi-head latent attention compresses key/value information into latent representations before reconstruction/use; sparse feed-forward routing activates selected experts. A multi-token training loss adds prediction targets at future offsets to the main causal objective.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Latent ranks, expert architecture, router balancing design, multi-token loss weights, precision, model version, and inference backend.
Fitting, fine-tuning, and adaptation
Use an implementation that faithfully supports the attention and expert layouts. For adaptation, verify adapter targets and router handling; full training needs the original numerical recipe. Validate task loss, expert balance, cache behavior, hardware efficiency, and retention of base capabilities after updates.
How to use and calibrate
Report task accuracy, cache memory, throughput, expert utilization, and numerical robustness under the actual deployment configuration. Use development data for settings and an independent test set for the final estimate. Report uncertainty across examples or seeds when the evaluation design supports it; model scores and self-assessments are not automatically calibrated probabilities of correctness.
Example application
Assess a sparse decoder for long-running generation where attention-cache memory matters.
Interpretation / pitfalls
Watch out
Published training efficiency is not automatically reproduced on different hardware or by loading weights in an unoptimized backend. The code below isolates one stated component; successful execution does not validate model quality or reproduce the cited experiment.
Python and R code examples
Full implementation route: Use officially documented or supported model implementations, verifying their attention and MoE support. R bridges Python via reticulate; the native example demonstrates low-rank key/value reconstruction, not a complete DeepSeek inference engine.
Example scope: A low-rank key/value reconstruction component relevant to latent attention; simplified.
Dependencies: Python 3 standard library; base R; shared setup above. No model downloads or external services.
Validation: Python component executed in the combined example script; R counterpart supplied but not runtime-tested here. All numbers are synthetic.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — A low-rank key/value reconstruction component relevant to latent attention; simplified.
Shared setup for this chapter
import math
def softmax(xs):
m = max(xs)
es = [math.exp(x-m) for x in xs]
return [e/sum(es) for e in es]
def dot(a, b):
return sum(x*y for x, y in zip(a, b))
def matvec(matrix, vector):
return [dot(row, vector) for row in matrix]
def meanvec(rows):
return [sum(row[j] for row in rows)/len(rows) for j in range(len(rows[0]))]
def sigmoid(x):
return 1/(1+math.exp(-x))
def nll(probabilities):
return -sum(math.log(p) for p in probabilities)
h = [0.4,-0.2,0.7]
latent = matvec([[0.5,0.1,-0.2],[0.2,0.3,0.4]],h)
key = matvec([[1,0],[0,1],[0.5,0.5]],latent)
print(latent,key)
Component demo, not a trained model — A low-rank key/value reconstruction component relevant to latent attention; simplified.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
h <- c(0.4,-0.2,0.7)
latent <- matrix(c(0.5,0.1,-0.2,0.2,0.3,0.4),2,byrow=TRUE) %*% h
key <- rbind(c(1,0),c(0,1),c(0.5,0.5)) %*% latent
print(list(latent=drop(latent),key=drop(key)))
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG039.