HN user

formalsystem

2,782 karma
Posts103
Comments218
View on HN
dev-discuss.pytorch.org 1y ago

Torch.load flipping default to weights_only=True

formalsystem
2pts0
codeforces.com 2y ago

The Meta Hacker Cup AI Track

formalsystem
1pts0
marksaroufim.substack.com 4y ago

Working Class Deep Learner

formalsystem
1pts0
twitter.com 4y ago

I refuse to let Amazon define Rust

formalsystem
1193pts339
www.pcgamer.com 4y ago

Dell is cancelling Alienware gaming PC shipments to several US states

formalsystem
23pts4
marksaroufim.substack.com 5y ago

Wild West of MLOps

formalsystem
3pts0
marksaroufim.substack.com 5y ago

Wild West of MLOps

formalsystem
3pts0
marksaroufim.substack.com 5y ago

Dump the MBA – Gaming as Management Training

formalsystem
2pts0
marksaroufim.substack.com 5y ago

The Rise of HuggingFace

formalsystem
1pts0
marksaroufim.substack.com 5y ago

The Rise of HuggingFace

formalsystem
2pts0
marksaroufim.substack.com 5y ago

The Rise of HuggingFace

formalsystem
2pts0
marksaroufim.substack.com 5y ago

The Myth of Objective Tech Screens

formalsystem
2pts0
marksaroufim.substack.com 5y ago

Machine Learning: The Great Stagnation

formalsystem
2pts0
medium.com 5y ago

Graphcore Announces Production Release of Pytorch for IPU

formalsystem
1pts0
marksaroufim.substack.com 5y ago

Machine Learning: The Great Stagnation

formalsystem
2pts0
marksaroufim.substack.com 5y ago

You're Doing Remote Wrong

formalsystem
2pts0
marksaroufim.substack.com 5y ago

You're Doing Remote Wrong

formalsystem
2pts0
marksaroufim.substack.com 5y ago

Machine Learning: The Great Stagnation

formalsystem
3pts0
marksaroufim.substack.com 5y ago

Machine Learning: The Great Stagnation

formalsystem
3pts0
marksaroufim.substack.com 5y ago

Machine Learning: The Great Stagnation

formalsystem
4pts0
h2.jaguarpaw.co.uk 5y ago

Automatic-Differentiation-Worked-Examples

formalsystem
3pts0
github.com 5y ago

Write Composable Software with Multiple Dispatch (Interactive Julia Notebook)

formalsystem
6pts0
arxiv.org 6y ago

Universal Differential Equations for Scientific Machine Learning

formalsystem
3pts1
www.nvidia.com 6y ago

Nvidia RTX Voice: Setup Guide

formalsystem
3pts0
github.com 6y ago

A high performance topological machine learning toolbox in Python

formalsystem
2pts0
medium.com 6y ago

The Art of Rhetoric

formalsystem
11pts0
medium.com 6y ago

Exterior Product

formalsystem
1pts0
medium.com 6y ago

Reinforcement Learning: Declarative Paradigm for Game AI. Reflections on yuri.ai

formalsystem
4pts0
medium.com 6y ago

Deschooling Society

formalsystem
1pts1
medium.com 6y ago

Deschooling Society

formalsystem
1pts0

I work on PyTorch and there are many things that make me suspicious about these results. My TL;DR is unless we get a zip file of all the kernels with how they're benchmarked results like this are almost impossible to verify

1. I don't have an M4 but I have an M1 Pro and I tried running the claimed 18x speedup VisionAttention attention example and I get close to identical runtimes. This example has more issues the main optimization the LLM is doing is a fusion and so not comparing to torch.compile is a bit sus. The numerics are off as well and I suspect the atols were way too big. Finally MultiHeadAttention is a deprecated API so using neither SDPA or torch.compile is a weird choice

2. In general 18x (and even some 100x speedups claimed near the end) are just a smell that some kernel is incorrect, the typical way you can get speedups like this is you don't warmup or you forget to synchronize. PyTorch has a lot of benchmarking footguns which is why sharing the exact eval scripts is helpful

3. Speaking of footguns, the shapes I saw in the examples were tiny, in that regime you're more often measuring noise as the primary bottleneck is not compute or memory but overhead

4. Generating many random shapes is also not so safe, some input distributions can make certain kernels trivial for example torch.randn() by default generates samples from a normal distribution with mean 0 and variance 1 and so if you take the mean of a large vector you're almost guaranteed to just get 0 esp if your tolerance is too high

5. KernelBench levels measure vastly different things and if you want to compare to PyTorch operators you want to focus on Level 1, Level 2 is fusions and so the right baseline is torch.compile and more reliable on nightlies. The Mamba 2 example (which I didn't run) also acknowledges that the primary thing it does is fusions which assuming everything is correct would still be strange to baseline vs eager

So please for everyone's sanity if you find a kernel that's 10-100x faster please share the exact code and benchmarking methodology to your smartest performance friends, you should be extremely skeptical of such results often you can discard some numbers based on a simple speed of light analysis. We all desperately want faster kernels but to get them we have to be really fanatical about correctness.

Please ignore my previous comments - I double checked with the model developers and here's the correction. Vanilla PTQ means no fancy quantization algorithm like SpinQuant, AWQ, etc. was applied. It just applied the same quantization scheme mentioned in the post (4bit per-group with g_size=32 symmetric weight, 8bit dynamic per token activation).

The issue here is memory in PyTorch is byte addressable and that's a limitation we can't solve without making a lot more changes to PyTorch. But in your specific case, if you'd like to pack more data into `values` you can use a combination of clever bit shifting, torch.cat and other bit twiddling pytorch like ops to pack more data. It's a trick we use quite heavily in torchao

It's particularly useful in memory bound workflows like batch size = 1 LLM inference where you're bottlenecked by how quickly you can send weights to your GPU. This is why at least in torchao we strongly recommend people try out int4 quantization.

At larger batch sizes you become compute bound so quantization matters less and you have to rely on hardware support to accelerate smaller dtypes like fp8

It's a great question! Int4 is an easy one to understand. PyTorch supports int8 but not int4 so what you can do is "pack" 2 int4 values into a single int8 value. You still get speedups even without hardware support because you're sending less data to the GPU and workloads like small batch size LLM inference are memory bandwidth bound and not compute bound. So indeed your intuition is correct you pack the values and before doing a matmul you "unpack" them back into an int8 and then upcast to fp16 to do a matmul

It's both! For this blog we decided to discuss our best end user facing numbers to keep things simple. We briefly hint at our contributor guide here https://github.com/pytorch/ao/issues/391 which does a tour of the APIs we provide developers implementing new algorithms

But we have had quantization algorithm developers such as HQQ or Autoround merge their code in to get composability and serialization for free. We view quantization algorithms as the top layer and going down you have quantized tensors, quant primitives like dequant/quant and finally basic dtypes like uint1-7 and float3-8. Personally why I spent so much time on AO was I was hoping we could make it easier for people to express their quantization algorithms in easy to read PyTorch code and if they must use custom kernels we also have some tutorials for how to integrate custom cuda and triton ops.

Most of those discussions have been happening on #torchao on discord.gg/gpumode so if you need to chat back and forth feel free to reach out to the team there otherwise Github also works.

There's different tradeoffs, spinning up a separate repo is what we call "out of core" vs having everything in PyTorch "in core"

Basically PyTorch is a large library where CI takes a long time to run which means merging code is hard and adding new dependencies is challenging and there are stringent constraints on BC breaking changes

Instead what torchao did and many other repos like torchtune, torchchat, torchtitan did was move out of core and it helps keep the core PyTorch library leaner with a smaller binary size and it really lets the team "out of core" focus on optimizing for their needs

Unfortunately the argument for what gets better changes over time, for example torch.compile initially a new repo called torchdynamo was built out of core to move fast but eventually merged back because everyone wanted to use it. Now torch.compile dev velocity is still quite fast and so now we have to tell people to use nightlies instead of official stable releases to which some people have asked me why don't you move torch.compile out of core

My 2c is the ecosystem will be much stronger and teams can move faster if they develop out of core so that's the tradeoff we picked for torchao. We managed to for example merge a few custom CPP kernels like fp6 or Marlin that would have challenging to motivate in core since those are still quite experimental and need to stand the test of time.

Mostly comes down to what's fastest to develop, it's faster to write a few custom kernels than it is to develop a new compiler backend

Granted after more upfront effort compilers are just such a significant UX boost that indeed you are making me question why I don't spend more time working on this myself lol

There's a bunch of overhead associated with PTQ - but TL;DR is that much of that overhead goes away when you're using `torch.compile()` and `torchao.autoquant()`

Essentially the latency overhead comes from quantizing and dequantizing weights and activations. For large layers this overhead is small because by quantizing your weights for example you reduce memory bandwidth pressure but for small layers the overhead of potentially looking up a table, reading scaling factors, quantization/dequantization and finally handling zero points might not be worth it.

However, even if such overhead exists you can still quantize your model and get it to be smaller it might not be faster is the problem. We solve the speed problem in 2 ways - `torch.compile()` will fuse operations like a dequant and matmul into a single kernel and `torchao.autoquant()` will do kernel level profiling to see whether a layer is actually made faster when quantizing and if not it skips quantizing that layer.

Most of our performance relies on leveraging torch.compile which generates Triton kernels which run fast on CPU and GPU but not MPS since Triton does not support generating Metal kernels. So you lose the nice story of writing low bit code in pure PyTorch but also get it running fast.

In these cases the only path forward we have is writing custom Metal kernels and plugging those in. That work is still ongoing and we'll hopefully have more to share soon.

nvtop or nvidia-smi gives you a good macro overview but I personally have found that utilization (EDIT: As reported by nvidia-smi) is actually a poor proxy for how fast your workload can be outside of just ensuring that a GPU is indeed being used

If you're here because you're interested in AI performance I'd recommend instead https://docs.nvidia.com/nsight-compute/NsightComputeCli/inde... to profile individual kernels. Nsight systems for a macro view https://developer.nvidia.com/nsight-systems and the PyTorch profiler if you're not authoring kernels directly but using something PyTorch https://pytorch.org/tutorials/recipes/recipes/profiler_recip...

This was a lot of fun to read, really enjoyed the journey from game design to product design to ML. One thing I was hoping to ask was how come you felt the need to procedurally generate levels? I've often heard debates around whether content needs to be "hand-crafted" to be worth another human's time but curious to hear your take on this since it seems like you implemented both ends of the spectrum with endless and classic.

Also do you feel like you now have a general set of principles to procedurally generate levels that apply to games outside of echo chess? Puzzle games are great since they're well scoped for indie devs and I'd imagine a lot of would be puzzle designers would burn out before they create a few dozen-hundred levels.

Gemini Earn 5 years ago

Am I missing something about crypto lending? Your deposit can't be FDIC insured and if borrowers are defaulting that means your deposit disappears. You can't bailout a crypto bank by printing crypto.

The appreciation of Bitcoin has been so staggering that it also makes getting interest back on your deposits seem rather outdated.

I find this kind of argument bizarre - if something is valuable to humans they will use energy for it whether it's for transportation, watching the Kardashians or mining Bitcoin. Saying one application of energy is moral and another is amoral neglects that people essentially vote with their time and energy what to consume it on.

If an application that uses a lot of energy is very valuable to people than it's a competitive advantage to also service that need with cheap energy.

Having sound money is not at odds with the environment.