|
In today's newsletter:
-
Fine-tune any LLM directly from Claude!
- Speculative decoding in LLMs.
- tSNE Projections can be misleading.
|
|
|
fine-tuning
We built a Hugging Face fine-tuning studio that lets you fine-tune any LLM directly from Claude:
The app connects to the HF Hub for model and dataset search. It handles chat template formatting for the training data, and lets you configure LoRA rank, quantization, batch size, and learning rate directly from Claude.
Training runs on HF’s GPU infra via AutoTrain.
Once training finishes, you can also chat with your fine-tuned model (or any other LLM on HF) directly from Claude
The studio’s built with the mcp-use SDK, an open-source full-stack framework to build MCP Apps for Agents.
In mcp-use, any MCP tool can be associated with a UI.
You define a tool handler, create a React component, and the mcp-use framework handles the tool registration, prop mapping between server and widget, bundling, and hot reload during development.
The widgets follow the MCP Apps standard, inspired by OpenAI’s Apps SDK.
You can find the mcp-use GitHub repo here →
And you can find the code for this fine-tuning studio here →
|
|
|
deep dive
Google uses speculative decoding in AI Overviews to serve over a billion Search users.
It’s also how Anthropic, Meta, and most major inference providers reduce latency at scale and get 2-3x more tokens per second, with mathematically identical outputs.
The loop has three steps, and the diagram below depicts how speculative decoding differs from standard decoding:
- A small model generates K candidate tokens autoregressively. Because it’s 10-100x smaller than the target, this costs roughly 1-2% of a target forward pass.
- Then a large model processes all
K draft tokens in a single forward pass, computing its distribution p(x) at each position. This parallel verification is structurally identical to prefill, so it saturates GPU compute instead of being memory-bandwidth bottlenecked like single-token decoding.
- Finally, each draft token is accepted or rejected by comparing the probability distributions of the small and large models. The algorithm walks through tokens sequentially. If token 3 is the first rejection, tokens 1-2 are accepted as-is (the small model got them right), the large model replaces token 3 with its own prediction (which it already computed during the verification pass), and tokens 4-5 are discarded without evaluation.
Note: Traditionally, both models must share the same tokenizer since verification compares probability distributions token-by-token. Universal Assisted Generation (UAG, Transformers 4.46+) relaxes this via text-level re-encoding, but same-tokenizer pairs remain faster because they skip that overhead.
In the best case, you get K+1 tokens from just one large model call.
And in the worst case, where every draft token is rejected, you still get 1 token from the large model, which is the same as standard decoding.
Implementation-wise, Hugging Face Transformers already exposes this as assistant_model in the generate() call:
For production serving, vLLM also supports this.
Here are some production tradeoffs:
-
The same tokenizer gives the best speedups. This is because when draft and target share a tokenizer, verification happens directly at the token ID level with zero overhead. Cross-tokenizer speculation also works, but it’s slow.
- Cross-tokenizer pairs → 1.5-1.9x speedup
- Same-tokenizer pairs → 1.5-3x speedup
-
A larger draft model will have a higher acceptance rate, but the drafting overheads themselves get expensive and eat the gains. For instance:
- Llama 3.2 1B as the drafter achieved 2.31x.
- The larger Llama 3.1 8B only hit 2.08x despite higher acceptance.
Eliminating the second model
The classic setup has three practical pain points.
- You need a matched draft model from the same family.
- The model consumes extra GPU memory.
Several variants have emerged to eliminate one or more of these.
- EAGLE removes the separate-model problem entirely. Instead of a standalone drafter, it trains a lightweight head (< 1B params) directly on the larger model’s hidden states.
- Medusa solves the same problem differently. It adds multiple prediction heads to the larger model, each predicting tokens at different future positions simultaneously.
- Self-speculative decoding (LayerSkip, SWIFT) eliminates both the extra model and the training requirement. It uses the target model’s own early layers as the drafter, then the full model for verification.
The direction is that speculative decoding is converging toward single-model solutions where the draft capability is built into the target model itself, either through trained heads or layer skipping.
For most production setups today, though, the two-model approach with a same-family drafter remains the simplest path to 2-3x speedups.
As further reading:
We covered the mechanics of LLM inference (prefill and decode phases, KV caching, speculative decoding, batching, and optimization techniques that improve latency and throughput here in the LLMOps course →
And we covered 72 techniques to optimize LLMs in production here →
Here’s the speculative decoding visual again for your reference:
|
|
|
machine learning
The performance of the tSNE algorithm heavily depends on perplexity—a hyperparameter of tSNE.
That is why it is also considered the most important hyperparameter in the tSNE algorithm.
Simply put, the perplexity indicates a rough estimate for the number of neighbors a point may have in a cluster.
And different values of perplexity create very different low-dimensional clusters, as depicted below:
While most projections depict the original three clusters, they vary significantly in shape.
So here are five key takeaways from the above graphic:
1) Never make any conclusions about the original cluster shape by looking at these projections.
- Different projections have different low-dimensional cluster shapes, and they do not resemble the original cluster shape.
- Although, in this case, the clusters were color-coded, which provided more clarity. But it may not always be the case since tSNE is an unsupervised algorithm.
2) Cluster sizes in a tSNE plot do not convey anything either.
3) The dimensions (or coordinates of data points) created by tSNE in low dimensions have no inherent meaning.
- The axes tick labels of the low-dimensional plots are different and somewhat random.
- Similar to PCA’s principal components, they offer little interpretability.
4) The distances between clusters in a projection do not mean anything.
- In the original dataset, the blue and red clusters are close.
- Yet, most projections do not preserve the global structure.
5) Strange things happen at perplexity=2 and perplexity=100.
-
At
perplexity=2, the low-dimensional mapping conveys nothing.
- As discussed earlier, the
perplexity value provides a rough estimate of the number of neighbors a point may have in a cluster.
- tSNE tries to maintain approx. 2 points per cluster. That is why the distortion.
- At
perplexity=100, the global structure is preserved, but the local structure gets distorted.
As a concluding note, ideal values typically lie in the range [5,50].
Next time you use tSNE, remember the above points, as these plots can get tricky to interpret.
If you are curious to learn more, we did a full 25-minute deep dive on tSNE.
It formulates tSNE from scratch and even implements it from scratch (using NumPy): Formulating and Implementing the tSNE Algorithm From Scratch.
|
|
|
|
|
NO-FLUFF RESOURCES TO...
All businesses care about impact. That’s it!
- Can you reduce costs?
- Drive revenue?
- Can you scale ML models?
- Predict trends before they happen?
We have discussed several other topics (with implementations) in the past that align with such topics.
Here are some of them:
All these resources will help you cultivate key skills that businesses and companies care about the most.
|
|
|
|
|
Partner with US
ADVERTISE TO 950k+ AI Professionals
Our newsletter puts your products and services directly in front of an audience that matters, including thousands of leaders, senior data scientists, machine learning engineers, data analysts, etc., around the world.
Get in touch today by replying to this email.
|
|
|