frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Hybrid Attention

22•JohannaAlmeida•2h ago
TLDR: Forked pytorch and triton internals . Changed attention so its linear first layer , middle quadratic layer, last linear layer Inference got much faster with a low perplexity hit in tests .

Full attention O(n²): 17.96s / 5.6 tok/s

HybridAttention O(n·W + n·D): 0.35s / 286.6 tok/s

I have been building a small Rust focused language model from scratch in PyTorch. This is not a finetune. It is byte level, trained from random initialization on a Rust heavy corpus assembled here: https://codeberg.org/JohannaJuntos/Sisyphus

Model and training setup

The model has 25.6M parameters with a 512 context length. It uses a byte level vocabulary of 256, with 8 layers, 8 heads, and 512 dimensional embeddings. Positional embeddings are learned and the embedding and LM head weights are tied.

Training ran for 30k steps on a 173.5M byte Rust corpus using a single RTX 4060 Ti 8GB.

Final metrics were a train loss of 0.5834, validation loss of 0.8217, and perplexity of 2.15. The best validation loss occurred around step 18.5k, which suggests some late overfitting or plateau.

Architecture

The model is a GPT style decoder, but replaces standard full attention with a HybridAttention block in each layer. This combines local windowed causal attention with a GRU like recurrent state path, along with a learned gate that mixes the two.

The local path handles short range syntax, while the recurrent path carries compressed long range state. The gate bias is initialized to favor local attention early in training.

Inference uses Triton kernels and custom torch.library ops.

Corpus

The biggest gain came from corpus expansion.

The run started with about 31MB from Rust official sources and major projects such as rustc, cargo, rust analyzer, tokio, serde, ripgrep, clap, and axum. The corpus was expanded to 173.5M bytes by cloning the top 500 crates, with 461 successful clones.

This expansion had more impact than any architectural change.

Inference performance

Full attention runs at about 5.6 tokens per second, while HybridAttention with KV cache reaches 286.6 tokens per second. This is about a 51x speedup with no visible quality loss.

The KV cache uses a hot window of 64 tokens in VRAM, while older tokens are compressed to 8 bit magnitude and angle and can be selectively promoted back to full precision. This changes the effective complexity from quadratic to near linear for this setup.

Quality

Surface Rust syntax looks decent, and imports and function signatures are often plausible. Semantics are still weak, and repetition and recursive patterns are common. It looks like Rust, but does not reason well yet.

What seems interesting

This project combines byte level Rust only pretraining from scratch, a hybrid local attention and recurrent architecture, large scale corpus expansion across the Rust ecosystem, and a practical KV cache paging strategy that delivers large speedups on consumer GPUs.

Next steps

I plan to run ablations comparing hybrid attention against local only and recurrent only variants, evaluate checkpoints around 18.5k versus the final model, and add syntax level validation such as parsing and compiling generated code. I also want to explore scaling context length from 256 up to 2048 and test whether switching from byte level to BPE becomes worthwhile now that the corpus is larger.

Questions

For small code models, which evaluations have been most useful beyond perplexity?

Has anyone seen hybrid local plus recurrent attention work well for code generation?

Given this setup, would you prioritize more tokens, longer context, or clean ablations first?

Comments

JohannaAlmeida•1h ago
Full attention O(n²): 17.96s / 5.6 tok/s

HybridAttention O(n·W + n·D): 0.35s / 286.6 tok/s

empath75•1h ago
Is this for just like auto complete, because you are not going to get anything very useful out of a code-only training set.
JohannaAlmeida•40m ago
Yeah auto complete is an amazing use case. I needed a small model that used transformers , could fit on my weak consumer GPU .

So i needed to make fundamental arquitecture changes .Do some KV cache tricks.

And then prove the new arquitecture was faster with benchmarks and perplexity was acceptable.

altruios•1m ago
I think it's more a proof of concept: locally trained. It would take lots of resources/time to train something non-trivial.
woodson•17m ago
Look into RWKV.
JohannaAlmeida•4m ago
Yeah RWKV is definitely related in spirit (recurrent state for long context). Here I’m combining local windowed attention with a gated recurrent path + KV cache compression, so it’s more hybrid than fully replacing attention

Teardown of unreleased LG Rollable shows why rollable phones aren't a thing

https://arstechnica.com/gadgets/2026/04/teardown-of-unreleased-lg-rollable-shows-why-rollable-pho...
1•DamnInteresting•38s ago•0 comments

Moving fast in hardware: lessons from lab to $100M ARR

https://blog.zacka.io/p/simplify-then-add-lightness-bc4
1•rryan•45s ago•0 comments

What Happened to the Ancient Bug Giants of 300M Years Ago?

https://nautil.us/what-happened-to-the-ancient-bug-giants-of-300-million-years-ago-1279562
1•Brajeshwar•51s ago•0 comments

What is 'muscle memory' and can I improve mine?

https://theconversation.com/what-is-muscle-memory-and-can-i-improve-mine-277471
2•Brajeshwar•59s ago•0 comments

My Blissful Week as a 'Do Not Disturb' Maximalist

https://www.wired.com/story/my-blissful-unbothered-life-as-a-do-not-disturb-maximalist/
1•Brajeshwar•1m ago•0 comments

The Story of Oil 1822–1922

https://www.thechemicalengineer.com/features/the-story-of-oil/
2•__natty__•1m ago•0 comments

First look at the evolution of early complex animals

https://apnews.com/article/fossil-animals-evolution-science-china-bizarre-a56a123cbad480e2c35f235...
1•gmays•1m ago•0 comments

AWS joins mass delusion that space based data centers make sense

https://aws.amazon.com/
1•boutell•1m ago•1 comments

Spooler Alert: Remote Unauth'd RCE-to-Root Chain in Cups

https://heyitsas.im/posts/cups/
1•hnpufflib•2m ago•0 comments

Optimizing SQLite for Servers

https://kerkour.com/sqlite-for-servers
1•randomint64•3m ago•0 comments

Claude Code is locking people out for hours

https://github.com/anthropics/claude-code/issues/44257
9•sh1mmer•4m ago•1 comments

Trump: 'a whole civilisation will die tonight'

https://www.bbc.co.uk/news/live/c5yw4g3z7qgt
2•xvxvx•4m ago•1 comments

Lunar Flyby

https://www.nasa.gov/gallery/lunar-flyby/
1•kipi•5m ago•0 comments

Building EU payment infra for agents

https://github.com/whire-ai/whire-python-sdk
1•pyjka•6m ago•1 comments

Show HN: Testreel – Programmatic product demo videos from JSON and Playwright

https://github.com/greentfrapp/testreel
1•greentfrapp•6m ago•0 comments

Why Japanese has words for feelings we tend to ignore (mono no aware)

https://rajavijayaraman.com/writing/mono-no-aware/
1•rajavijayaraman•6m ago•0 comments

Show HN: VibeAround – Use Claude Code, Codex, Cursor from IM, Built on ACP (

https://github.com/jazzenchen/VibeAround
1•jazzen•6m ago•0 comments

H1B Abuse Exposed in Growing Texas City [video]

https://www.youtube.com/watch?v=ralf0yL1Tfw
2•profdevloper•8m ago•0 comments

Show HN: Opensidian: Local-first notes in the browser with POSIX shell and sync

https://opensidian.com
1•braden-w•8m ago•0 comments

Show HN: Beta Testing needed for my package Trustcheck

https://github.com/Halfblood-Prince/trustcheck
4•halfblood1010•9m ago•0 comments

Ace-Step-1.5 playground- SOTA open source music model

https://mesmer.tools/free-tools/ai-music-maker
1•mesmertech•9m ago•1 comments

MCP-slim, an auto-optimizing MCP proxy that cuts 99% of token waste

https://github.com/uaziz1/mcp-slim
2•uaziz1•10m ago•2 comments

A WIP arbitrary precision arithmetic library (alternative to GMP)

2•Tommyrexx•11m ago•1 comments

ELN Finder to search and select a suitable Electronic Lab Notebook

https://eln-finder.ulb.tu-darmstadt.de/home
1•eamag•12m ago•0 comments

Seeking review: Signal-like protocol in Dart

https://github.com/Dritonsallahu/risaal-crypto
1•dritoonnss•13m ago•0 comments

Claude is having another moment, again

https://downdetector.co.uk/status/claude-ai/
6•ksajadi•15m ago•0 comments

How to Build an AI Agent for Slack with Chat SDK and AI SDK

https://vercel.com/kb/guide/how-to-build-an-ai-agent-for-slack-with-chat-sdk-and-ai-sdk
1•flashbrew•16m ago•0 comments

Goodclaude, CLI that lets you pet Claude (it meows too)

https://github.com/Ijtihed/goodclaude
1•ijtihed1•16m ago•1 comments

Claude Login Down?

https://downdetector.com.br/en/status/claude-ai/
7•raimille1•17m ago•3 comments

The (First?) Social Media Addiction Trial

https://12gramsofcarbon.com/p/tech-things-social-media-addiction
1•theahura•17m ago•0 comments