frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Getting AI to write good SQL

https://cloud.google.com/blog/products/databases/techniques-for-improving-text-to-sql
223•richards•7h ago•114 comments

Wow@Home – Network of Amateur Radio Telescopes

https://phl.upr.edu/wow/outreach
34•visviva•2h ago•0 comments

Thoughts on thinking

https://dcurt.is/thinking
336•bradgessler•9h ago•226 comments

Show HN: KVSplit – Run 2-3x longer contexts on Apple Silicon

https://github.com/dipampaul17/KVSplit
208•dipampaul17•8h ago•32 comments

Postman for MCP

https://usetexture.com/##
19•andes314•2h ago•3 comments

XTool – Cross-platform Xcode replacement

https://github.com/xtool-org/xtool
30•TheWiggles•2h ago•11 comments

A Linux kernel developer plays with Home Assistant: general impressions

https://lwn.net/SubscriberLink/1017720/7155ecb9602e9ef2/
8•pabs3•1h ago•0 comments

A Research Preview of Codex

https://openai.com/index/introducing-codex/
390•meetpateltech•13h ago•312 comments

Rustls Server-Side Performance

https://www.memorysafety.org/blog/rustls-server-perf/
70•jaas•3d ago•10 comments

MIT asks arXiv to withdraw preprint of paper on AI and scientific discovery

https://economics.mit.edu/news/assuring-accurate-research-record
265•carabiner•13h ago•143 comments

Coding agent in 94 lines of Ruby

https://radanskoric.com/articles/coding-agent-in-ruby
69•radanskoric•2d ago•22 comments

ClojureScript 1.12.42

https://clojurescript.org/news/2025-05-16-release
113•Borkdude•8h ago•20 comments

I'm Peter Roberts, immigration attorney, who does work for YC and startups. AMA

192•proberts•13h ago•358 comments

Show HN: Visual flow-based programming for Erlang, inspired by Node-RED

https://github.com/gorenje/erlang-red
207•Towaway69•13h ago•90 comments

WebGL Gray-Scott Explorer (2012)

http://www.mrob.com/pub/comp/xmorphia/ogl/index.html
16•joebig•3h ago•2 comments

X X^t can be faster

https://arxiv.org/abs/2505.09814
166•robinhouston•12h ago•47 comments

MCP: An in-depth introduction

https://www.speakeasy.com/mcp/mcp-tutorial
36•ritzaco•3d ago•14 comments

The Joys of Discovering the Roman Underground

https://www.smithsonianmag.com/travel/the-joys-of-discovering-the-roman-underground-from-the-colosseum-to-whats-beneath-the-trevi-foundation-180986626/
3•ulrischa•1d ago•0 comments

They Were Identical 'Twinnies' Who Charmed Orwell, Camus and More

https://www.nytimes.com/2025/05/04/books/review/the-dazzling-paget-sisters-ariane-bankes.html
20•lermontov•5h ago•4 comments

Will AI systems perform poorly due to AI-generated material in training data?

https://cacm.acm.org/news/the-collapse-of-gpt/
66•pseudolus•5h ago•70 comments

Behind Silicon Valley and the GOP’s campaign to ban state AI laws

https://www.bloodinthemachine.com/p/de-democratizing-ai
22•spenvo•1h ago•4 comments

New high-quality hash measures 71GB/s on M4

https://github.com/Nicoshev/rapidhash
17•nicoshev11•2d ago•4 comments

Java at 30: Interview with James Gosling

https://thenewstack.io/java-at-30-the-genius-behind-the-code-that-changed-tech/
172•chhum•15h ago•253 comments

Show HN: Roast My Dish – AI roasts your food photos with brutal honesty

https://www.roastmydish.online/
14•romeumaleiane•3h ago•6 comments

The first year of free-threaded Python

https://labs.quansight.org/blog/free-threaded-one-year-recap
250•rbanffy•18h ago•252 comments

Material 3 Expressive

https://design.google/library/expressive-material-design-google-research
331•meetpateltech•3d ago•513 comments

Show HN: Solidis – Tiny TS Redis client, no deps, for serverless

https://github.com/vcms-io/solidis
39•jayl-e-e•7h ago•4 comments

The Magic Hours: The Films and Hidden Life of Terrence Malick

https://www.lrb.co.uk/the-paper/v47/n09/david-thomson/cool-tricking
53•mitchbob•10h ago•31 comments

Foundry (YC F24) Is Hiring – Founding Engineer (ML × SWE)

https://www.ycombinator.com/companies/foundry/jobs/uwi8b6I-founding-engineer-ml-x-swe
1•lakabimanil•11h ago

GitHub Models API now available

https://github.blog/changelog/2025-05-15-github-models-api-now-available/
5•msolujic•23m ago•0 comments
Open in hackernews

Show HN: KVSplit – Run 2-3x longer contexts on Apple Silicon

https://github.com/dipampaul17/KVSplit
208•dipampaul17•8h ago
I discovered that in LLM inference, keys and values in the KV cache have very different quantization sensitivities. Keys need higher precision than values to maintain quality.

I patched llama.cpp to enable different bit-widths for keys vs. values on Apple Silicon. The results are surprising:

- K8V4 (8-bit keys, 4-bit values): 59% memory reduction with only 0.86% perplexity loss - K4V8 (4-bit keys, 8-bit values): 59% memory reduction but 6.06% perplexity loss - The configurations use the same number of bits, but K8V4 is 7× better for quality

This means you can run LLMs with 2-3× longer context on the same Mac. Memory usage scales with sequence length, so savings compound as context grows.

Implementation was straightforward: 1. Added --kvq-key and --kvq-val flags to llama.cpp 2. Applied existing quantization logic separately to K and V tensors 3. Validated with perplexity metrics across context lengths 4. Used Metal for acceleration (with -mlong-calls flag to avoid vectorization issues)

Benchmarked on an M4 MacBook Pro running TinyLlama with 8K context windows. Compatible with Metal/MPS and optimized for Apple Silicon.

GitHub: https://github.com/dipampaul17/KVSplit

Comments

nico•8h ago
Great work. This seems very interesting, but I need something slightly more high level to relate to it

Will it just allow me to run let’s say a model with a 2048 token context window with a 4-6k context window? Or a 128k model (like gemma3) with a 256k+ context window?

What’s the ideal use case for local models?

Thank you

dipampaul17•7h ago
With the K8V4 configuration providing 59% memory savings, you can effectively run contexts 2.4× longer on the same hardware. A model with a 2048 token context can now handle about 5000 tokens, while an 8K context model can reach approximately 19.5K tokens.

In practical terms, this means processing entire books at once on a MacBook, analyzing large codebases without splitting files, or maintaining comprehensive conversation history in chat applications.

The memory savings scale linearly with context length - the longer your context window, the more absolute memory you save. On my M4 MacBook with 8K context, I reduced KV cache from 176MB to 72MB. At 128K context, that same percentage saving would free up gigabytes.

This optimization is most valuable when you're context-window limited rather than model-parameter limited. If you're hitting OOM errors due to long inputs rather than large model weights, KVSplit directly addresses your bottleneck.

kmacdough•7h ago
> Will it just allow me to run let’s say a model with a 2048 token context window with a 4-6k context window

It reduces the memory footprint of a particular model. You can do what you like with that. Extending the context window post-training isn't trivial, so unless you know what you're doing, you'd be better off finding a model trained on a larger context window.

Many uses for local models like working offline or privacy/security. Most folks, though, are using it to experiment with tweaking models.

nico•7h ago
Will that make the model run/feel faster?

I can run models with 30-40b parameters on my computer, but they feel a lot slower than the 1-7b ones

So would this make the 30-40b parameter modes run faster? Or at least “feel” faster?

fennecbutt•3h ago
No, only more compute or fancy model architecture tweaks will get you more t/s.

However if using discrete gpu, reducing KV memory lets you load more layers onto gpu and therefore more performance, but only if you're already struggling to fit your model into vram.

dipampaul17•2h ago
For 30-40B parameter models, you'll see two types of performance impacts:

First, there's a direct throughput improvement – our benchmarks show a 14.5% speed increase with K8V4 versus FP16. This comes from better memory bandwidth utilization when processing the KV cache.

However, this won't make a 30B model suddenly feel as responsive as a 7B model. The fundamental computation bottleneck remains – larger models need more matrix multiplications regardless of how efficiently you store the KV cache.

Where you might notice a bigger difference is in handling longer inputs. With 59% less memory used for KV cache, your system can dedicate more resources to computation rather than memory management, which can reduce stuttering during processing long documents.

The most noticeable improvement would be if you're currently hitting memory limits that force you to segment long inputs. Being able to process everything in one pass eliminates those artificial breaks.

@fennecbutt is spot-on that the core token generation speed is primarily determined by compute capability and model architecture. KVSplit complements those factors by optimizing memory usage, not by fundamentally changing the computation path.

badmonster•7h ago
I'm curious: is it possible to apply differentiated KV quantization (like K8V4) to models after they're already converted to .gguf format, or does this require rebuilding the model with special support? If it's compatible with any .gguf file, are there any limitations on model types (e.g. Mistral, Phi-3, etc.) or tokenizer configs?
dipampaul17•7h ago
Yes, that's one of the key benefits - KVSplit works with any existing .gguf model without requiring reconstruction or special conversion. The quantization happens at runtime on the KV cache, not during model loading or conversion.

This works because the KV cache is created during inference as tokens are processed, completely separate from the model weights themselves. The --kvq-key and --kvq-val flags simply tell llama.cpp how to store these intermediate tensors in memory.

I've tested it successfully with:

- Llama-3 models - Mistral models - Phi-2/Phi-3 - TinyLlama - Qwen variants

The only limitation is that it requires llama.cpp's Metal backend, and you need to disable Flash Attention with -fa 0 since the current FA implementation in llama.cpp bypasses the custom KV cache format. The technique itself should work with any transformer architecture that uses a standard attention mechanism.

fennecbutt•3h ago
I thought flash attention was required for quantised KV?
entrepy123•7h ago
Are these significantly faster/better on 64GB or 128GB Apple silicon (over 36GB or 48GB)?

I've been reading that large contexts and large models are just painfully slow, even on the fastest and largest Apple silicon that money can buy.

So I wonder if this helps make more use of greater memory, or if really smallish models are still where it's at for Apple silicon, practically speaking.

dipampaul17•2h ago
The memory savings from KVSplit scale proportionally with context length, so higher-RAM Macs (64GB/128GB) benefit even more in absolute terms. On a 128GB Mac Studio, you could potentially handle context windows in the hundreds of thousands of tokens.

However, KVSplit doesn't fundamentally change computation speed - just memory efficiency. Our benchmarks show a 14.5% throughput improvement with K8V4, but this comes from better memory locality, not reduced computation.

The "painfully slow" issue with large models on Apple Silicon stems primarily from the compute limitations, not memory constraints. A 70B parameter model will still run at similar token generation speeds regardless of available RAM or KV cache optimizations.

What KVSplit does is make better use of whatever memory you have available. It's particularly valuable when your bottleneck is context length rather than model size.

For practical Apple Silicon usage, the sweet spot remains smaller models (7B-13B) with now-expanded context windows. This lets you process significantly more text while maintaining reasonable generation speeds.

If your workflow needs both massive contexts AND large models, you'd still want to consider server-grade GPUs, but KVSplit helps push the boundary of what's feasible on Apple hardware.

hiatus•2h ago
Is this any different from using --cache-type-k and --cache-type-v?
andrewmcwatters•2h ago
Thank you for these insights!
behnamoh•7h ago
Is this patch possible to do on MLX? I'm getting better speeds on MLX. That, combined with your approach, would finally let Mac users have long conversations at usable speeds.
landl0rd•31m ago
Probably but I am currently deep in the MLX weeds and finding out that though it's a well-designed framework it's much less mature in terms of example code you can steal where someone has already benchmarked the "best way" to do something.

My biggest hope for it is actually Haskell bindings believe it or not. Someone pointed out the other day its laziness makes it fit really well for that paradigm and the more or less pure-function approach to the compile graph helps too. ML in Haskell would be fun.

matheist•7h ago
Looks interesting! Is there any intuition for why this should be the case? Did you discover it via that intuition, or just random experimentation?

A note, your install script appears to still have a placeholder at the "apply patch" step. A suggestion, might be more user-friendly to fork llama.cpp and then include that as a git submodule rather than make it a "git clone and apply patch" step.

A further note, everyone and their dog has a different local python set-up, might be nice to let people separate the llama.cpp stuff from the python stuff rather than bake in a dependence on homebrew python.

dipampaul17•2h ago
Great question about the intuition! The difference comes from the core roles these components play in attention.

Keys determine which tokens to attend to - they create the actual attention pattern through similarity calculations. Values only store what information gets passed forward once attention is decided.

When a key vector is quantized too aggressively, it distorts the similarity calculations for every token interaction. A small error in keys can completely redirect attention to the wrong tokens.

Values, however, are much more forgiving. When a value vector is quantized, any error only affects the specific information content of that single token after the attention pattern is already established.

It's like a library catalog system vs. the books themselves. If catalog numbers (keys) are corrupted, you'll look in completely wrong sections. If some words in books (values) are smudged, you're still reading the right book - just with occasional noise.

Mathematically, keys participate in softmax calculations where small errors get exponentially amplified through the normalization process. Values just undergo linear weighted averaging, where errors tend to cancel out.

I first encountered this asymmetry in papers like "More for Keys, Less for Values" and "KV-AdaQuant," but wanted to quantify exactly how it impacts Apple Silicon inference. The 7× quality difference between K8V4 and K4V8 using identical memory was striking.

Thanks for the installation feedback too! I'll fix the placeholder and make the Python dependencies more flexible.

gervwyk•2h ago
Great explanation thanks for this!
vlovich123•18m ago
My understanding is that the roles of KVQ aren’t actually well understood and that while they’re called key/value/query tensors it’s not quite straightforward to tease out what they mean or the role they play.
ondra•7h ago
Is this any different from using --cache-type-k and --cache-type-v?
azinman2•5h ago
That’s what I want to know!
landl0rd•29m ago
I'm guessing it's a bit different since MLX/MPS doesn't have native 4-bit support (or even 8 if I remember correctly?) It didn't launch with bf16 support even. So I think the lowest you could go on the old type_k/v solution and apple GPUs was 16-bit f16/bf16 but not a llama.cpp internals expert so maybe wrong?
smcleod•7h ago
+0.86% perplexity it's quite a bit at such a small context size though isn't it? How is it at more reasonable context sizes like 64-128k?
nomel•5h ago
> This means you can run LLMs with 2-3× longer context on the same Mac. Memory usage scales with sequence length, so savings compound as context grows.

The point seems to be that this reduces memory footprint. This makes it possible to run longer context, for the same limited memory, if you couldn't before. Or, you can use that free memory to do something else, like an IDE.

smcleod•4h ago
Yeah I get that, that's what we yse k/v cache quantisation for now which has a lower impact on PPL than this unless I'm missing something?
dipampaul17•2h ago
You're right to question the perplexity impact - 0.86% isn't negligible. Our extended testing shows this impact remains fairly consistent across context lengths up to 16K, which was our test limit.

We haven't benchmarked at 64-128K contexts yet, but theoretically the relative perplexity impact should remain stable. The absolute impact could potentially compound with very long contexts, though.

The key difference from standard KV quantization is the asymmetric approach. Most implementations use K8V8 (8-bit for both) which has a 0.03% perplexity impact but only 47% memory savings. K8V4 pushes this to 59% savings with the 0.86% quality tradeoff.

For reference, the quality impact is still well below the typical 5% threshold where differences become noticeable in generated text. It's a reasonable tradeoff for the additional memory savings, especially at long contexts.

@smcleod - We're using the same underlying quantization methods, just applying them asymmetrically between keys and values. If your existing approach already uses lower precision for values than keys, you're likely getting similar benefits.

3abiton•5h ago
This is a brilliant idea, and initiative. Does this also apply to GPUs? And I assume should be compatible with other quantization techniques, albeit they probably require their own patches?
dipampaul17•2h ago
Yup, this approach would likely work on NVIDIA/AMD GPUs as well - the underlying principle that keys require higher precision than values is hardware-independent.

The CUDA backend in llama.cpp already supports separate cache type settings with the `--cache-type-k` and `--cache-type-v` flags. Our particular patch is focused on Metal-specific optimizations, but the core technique transfers directly.

Regarding compatibility with other quantization methods - absolutely. This KV cache optimization is complementary to model weight quantization (Q4_K_M, GPTQ, AWQ, etc.). You can combine asymmetric KV cache precision with any model weight format.

Since KV cache quantization happens at runtime while processing tokens (separate from model weights), it doesn't conflict with how the model itself is quantized. They operate on different parts of the inference pipeline.

What would require additional work is integrating with specialized inference engines that have custom KV cache handling, like vLLM or TensorRT-LLM. Each would need its own implementation of asymmetric KV precision.

The most immediate GPU benefit would likely come from integrating these insights into the FlashAttention implementation directly, where the memory bandwidth savings could translate to even greater speedups on CUDA hardware.

therealsmith•5h ago
Am I missing something? As far as I can see this patch does nothing except add new options that replicate the functionality of the existing --cache-type-k and --cache-type-v options.

Using `--flash-attn --cache-type-k q8_0 --cache-type-v q8_0` is a very well known optimization to save VRAM.

And it's also very well known that the keys are more sensitive to quantization than values. E.g. https://arxiv.org/abs/2502.15075

Aurornis•3h ago
> Using `--flash-attn --cache-type-k q8_0 --cache-type-v q8_0`

I think you meant ‘--cache-type-v q4_0’

I would also like an explanation for what’s different in this patch compared to the standard command line arguments.

zmmmmm•4h ago
Amazing!

Curious, what happens to performance? I assume you still pay the same performance price for longer context, even if you can now fit it in memory.

fennecbutt•3h ago
I think this is true, I've found I get roughly the same iteration speed for prompt processing no matter if the cache is fp16, q8 or q4.

It doesn't make sense to me though, I haven't looked into how it works inside but I would've thought it would pack vectors and then do 4-8b simd on all of them at once, but it really seems like it's not packing em.