12 comments

  • ollin6 hours ago
    This post is a classic! Also recommended: Horace also gave a related talk (covering the high-level picture of modern ML Systems) at Jane Street in Dec 2024 <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=139UPjoq7Kw" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=139UPjoq7Kw</a>
  • liuliu2 hours ago
    One thing people seems not to acknowledge, and this post made it super clear is that NVIDIA kept their lead extremely well in a few years of very high growth. The TFLOPs, the bandwidth, the interconnect mentioned in this post continues to grow at exponential rate with no sign of stopping yet. This is a 30-year-old incumbent reminding you. The willingness to compete from NVIDIA is just simply remarkable.
  • ThouYS5 hours ago
    I feel like there is no portable advice for performance. A torch model exported as onnx is a different model.<p>That onnx model run using onnxruntime with cuda ep is a different model than the one run with TRT ep.<p>And even among the same runtime, depending on the target hardware and the memory available during tuning, the model behaves differently. It is a humongous mess
  • xiaod3 hours ago
    I&#x27;d want to see more about the failure modes. Production systems need graceful degradation more than optimal performance.
  • tosh11 hours ago
    &gt; in the time that Python can perform a single FLOP, an A100 could have chewed through 9.75 million FLOPS<p>wild
    • patmorgan2310 hours ago
      Why are we comparing a programing language and a GPU. This is a category error. Programing languages do not do any operations. They perform no FLOPs, they are the thing the FLOPs are performing.<p>&quot;The I7-4770K and preform 20k more Flops than C++&quot; is an equally sensible statement (i.e. not)
      • gchamonlive8 hours ago
        &gt; Why are we comparing a programing language and a GPU.<p>You are taking the statement too literally and forgetting it&#x27;s a figure of speech, specifically metonymy.<p>When the author says it&#x27;s millions of flops faster in a gpu than in an interpreteted programming language, it&#x27;s not comparing them directly, but algorithms that run in them, so the substitution is the algorithms for the tools used to implement&#x2F;run them.<p>It makes sense if you say &quot;running similar logic -- like multiplying vectors and matrices -- on the CPU is millions of flops slower then on the GPU&quot;. There is no category error there.
      • tosh9 hours ago
        the sentence is ambiguous because &quot;Python&quot; can mean python + a certain library and even a different Python implementation<p>but I find it illuminating to compare what a certain hardware can do in principle (what is possible) vs what I can &quot;reach&quot; as programmer within a certain system&#x2F;setup<p>in this case NVIDIA A100 vs &quot;Python&quot; that does not reach a A100 (without the help of CUDA and PyTorch)<p>another analogy:<p>I find it useful to be able to compare what the fastest known way is to move a container from A to B using a certain vehicle (e.g. truck) and how that compares to how fast a person that can not drive that truck can do it + variants of it (on foot, using a cargo bike, using a boat via waterway, …)<p>I&#x27;m also interested in how much energy is needed, how much the hw costs and so on<p>Often there are many ways to do things, comparing is a great starting point for learning more
        • tosh8 hours ago
          related to the truck analogy: an advantage of the way slower Python approach is: it does not need a GPU<p>that said: Python can get to more FLOPs by changing the representation: <a href="https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;array.html" rel="nofollow">https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;array.html</a>
      • smasher1647 hours ago
        &gt; This is a category error.<p>Okay, but surely you know what they actually mean right, or are you being willfully obtuse? They are comparing CPython (the <i>main</i> python implementation)&#x27;s implementation that runs on the CPU with a kernel running on the GPU.
        • bee_rider7 hours ago
          I’m not 100%, in context. Sorry for the big quote:<p>&gt; Overhead is when your code is spending time doing anything that&#x27;s not transferring tensors or computing things. For example, time spent in the Python interpreter? Overhead. Time spent in the PyTorch framework? Overhead. Time spent launching CUDA kernels (but not executing them)? Also... overhead.<p>&gt; The primary reason overhead is such a pernicious problem is that modern GPUs are really fast. An A100 can perform 312 trillion floating point operations per second (312 TeraFLOPS). <i>In comparison, Python is really slooooowwww. Benchmarking locally, Python can perform 32 million additions in one second.</i><p>&gt; That means that in the time that Python can perform a single FLOP, an A100 could have chewed through 9.75 million FLOPS.<p>&gt; <i>Even worse, the Python interpreter isn&#x27;t even the only source of overhead - frameworks like PyTorch also have many layers of dispatch before you get to your actual kernel.</i> If you perform the same experiment with PyTorch, we can only get 280 thousand operations per second. Of course, tiny tensors aren&#x27;t what PyTorch is built for, but... if you are using tiny tensors (such as in scientific computing), you might find PyTorch incredibly slow compared to C++.<p>Emphasis mine.<p>It’s all a bit jumbled up. I get that he was going for an informal tone and this isn’t exactly a benchmark. But I’m still not sure, based on the second emphasized part I think the “bad” measurements are coming from Python+PyTorch but with too-small workloads, and dispatching to CPU, maybe? But the first one looks like naive Python loops.
    • p1esk10 hours ago
      This statement makes zero sense
    • tosh9 hours ago
      re comments:<p>yes of course this is apples to oranges but that&#x27;s kind of the point<p>it shows the vast span between specialized hardware throughput IFF you can use an A100 at its limit vs overhead of one of the most popular programming languages in use today that eventually does the &quot;same thing&quot; on a CPU<p>the interesting thing is why that is so<p>CPU vs GPU (latency vs throughput), boxing vs dense representation, interpreter overhead, scalar execution, layers upon layers, …
      • p1esk8 hours ago
        A100 FP32 throughput “at its limit”: 19.5 TFLOP&#x2F;s.<p>AMD EPYC 9965 FP32 throughput “at its limit”: 41.2 TFLOP&#x2F;s (192 cores x 64 FP32 FLOP&#x2F;cycle&#x2F;core x 3.35GHz).
        • zzzoom4 hours ago
          EPYC 9965: 614GBps of 12-channel DDR5-6400<p>A100: 1935GBps of HBM2e<p>Most of those FLOPS are constrained by memory bandwidth.
          • Const-me1 hour ago
            &gt; Most of those FLOPS are constrained by memory bandwidth<p>I believe inference with large enough batch size is almost always compute bound, simply due to algorithmic complexity.<p>Each step of tiled matric multiplication with square tiles of size N^2 takes O(N^2) memory loads and O(N^3) compute operations. With N = 32 or 64, you will likely saturate compute even on iGPUs with DDR4 or DDR5 memory pretending to be VRAM.
        • aesthesia3 hours ago
          That&#x27;s also a CPU that came out four years later than the A100. The contemporaneous B200 is not optimized for FP32 and does 74.45 TFLOP&#x2F;s. For FP16 it&#x27;s at ~2 PFLOP&#x2F;s.
          • p1esk2 hours ago
            The point is that modern CPUs are not as slow as most DL people think. Roughly 10x slower but with a lot more memory.
        • tosh8 hours ago
          A100: 312 TFLOP&#x2F;s for FP16<p>but it is very impressive how far modern CPUs get as well (also in smart phones!)
          • p1esk8 hours ago
            Intel Xeon 6980P: 128 cores x 1024 FP16 FLOP&#x2F;cycle&#x2F;core x 3.2 GHz: 419 TFLOP&#x2F;s
            • tosh7 hours ago
              I&#x27;m not saying &quot;GPU more brrt than CPU&quot;<p>I found the comparison interesting<p>on Intel Xeon 690P with 419 TFLOP&#x2F;s it is still (maybe even more?) interesting to ask:<p>how much throughput can you reach with Python, Python with lib x, y, z, with C++ like this, with C++ like that etc etc and why?<p>no?
              • p1esk6 hours ago
                No one in their right mind would use pure Python to do matrix multiplication. It’s like using a screwdriver to hammer nails into wood.<p>But this discussion is even more bizarre than comparing a screwdriver to a hammer, it’s like comparing a screwdriver to a nail.
    • itishappy8 hours ago
      Which, lets be honest, is probably still being orchestrated by Python somewhere.<p>Python is 9.75 million times faster than Python.
      • giancarlostoro8 hours ago
        I was researching if there was much benefit to using Rust or C++ over Python for AI, and turns out, the GPU doesn&#x27;t care once the instructions are in because its an entirely different spec running on the GPU. The only thing you might save on is &quot;startup&quot; costs of getting your code into the GPU I guess? I assume that time cost is miniscule though, once its all in memory, nobody cares that you spent any time &quot;booting it up&quot; any more than how long Windows takes these days.
        • BillStrong7 hours ago
          As long as you don&#x27;t keep calling out to the CPU, that is.<p>Tool calling, searches, cache movement if used, and even debug steps all stall the GPU waiting for the CPU.<p>There was a test of turning one of the under 1B Qwen3+ models into a kernel that didn&#x27;t stall by the CPU as one GPU pass that saw quite a bit f perf lift over vLLM, I believe, showing this is an issue still.<p>Its been a month, so I don&#x27;t remember more details than this.
        • hashmap5 hours ago
          you can port anything python is doing with a couple prompts into rust&#x2F;c++, including parity validation. when the barrier to migrating is that thin, you are losing money and time even continuing to talk about it. python is miserably slow, so dont let it touch any part of your system. no snakes in the house.
        • jmalicki6 hours ago
          Pytorch dataloaders are often horribly inefficient, a lot of stuff there can benefit from Rust&#x2F;C++
    • xyzsparetimexyz10 hours ago
      Single core vs multi core accounts for much of this
      • cdavid10 hours ago
        Not really. GPU many cores, at least for fp32, gives you 2 to 4 order of magnitudes compared to high speed CPU.<p>The rest will be from &quot;python float&quot; (e.g. not from numpy) to C, which gives you already 2 to 3 order of magnitude difference, and then another 2 to 3 from plan C to optimized SIMD.<p>See e.g. <a href="https:&#x2F;&#x2F;github.com&#x2F;Avafly&#x2F;optimize-gemm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Avafly&#x2F;optimize-gemm</a> for how you can get 2 to 3 order of magnitude just from C.
        • p1esk8 hours ago
          Theoretical FP32 performance of AMD EPYC 9965 is double that of A100: 41.2 TFLOP&#x2F;s vs 19.5 TFLOP&#x2F;s
          • fc417fc8021 hour ago
            Isn&#x27;t that because the A100 is optimizing for memory bandwidth per TF?
  • big-chungus46 hours ago
    How does x.cos().cos() work faster than doing two cos calls separately? Like the first cos call returns a tensor either way, the only difference is that it&#x27;s not assigned to a variable. But how is it even possible know that difference in python?
    • vrm6 hours ago
      It’s really not a concept you can express in idiomatic Python very easily. This comes from the actual generated assembly involving copies from global GPU memory into registers (slow, bandwidth saturates quickly) and back in between the cosines. If you can avoid the intermediate roundtrip that cuts the cost approximately in half.
    • ollin6 hours ago
      Yeah, that part should not be read literally; `x.cos().cos()` and `x1 = x.cos(); x2 = x1.cos()` both launch the same number of kernels (two in unfused&#x2F;eager mode, one in fused&#x2F;torch.compile, see this test notebook [1]). I think the author chained the two cos calls to symbolize the idea of combining them (without exposing the intermediate result), but chaining the two cos calls doesn&#x27;t literally trigger operator fusion.<p>[1] <a href="https:&#x2F;&#x2F;colab.research.google.com&#x2F;drive&#x2F;13a4Y-ko6QLMPAhBz64cRkdqxOT7LFHaF?usp=sharing" rel="nofollow">https:&#x2F;&#x2F;colab.research.google.com&#x2F;drive&#x2F;13a4Y-ko6QLMPAhBz64c...</a>
  • marketingan6 hours ago
    Deep learning is just glorified linear algebra. Master the progression: Feed-forward CNN RNN LSTM Attention. You don&#x27;t even need a GPU to understand the climax; Karpathy’s llama2.c implements a full transformer inference engine in just ~300 lines of C using SIMD pragmas for CPU execution.
    • miki1232115 hours ago
      I wish more people pursued that approach to teaching neural networks.<p>First teach what the network does and why, writing it as a loopy, inference-only Python function. Explain training only in an abstract way, E.G. with the &quot;take a random weight, twist it a little and see if the loss improves&quot; algorithm. This lets you focus on the architecture and on why it is what it is.<p>Then, teach the intuitions behind derivatives and gradient descent. You don&#x27;t need the entirety of calculus, there&#x27;s no benefit to knowing how a sequence or limit works if you ) only want to understand neural networks. With autograd, you won&#x27;t be manually doing derivatives of weird functions either, so intuitive understanding is a lot more important than doing dozens of traditional calculus exercises on paper like it&#x27;s the 1800s. You could probably explain the little bit of calculus you need in an hour or two, even to somebody with a 12-year-old&#x27;s understanding of math and a good bit of programming knowledge.<p>Only when people understand the training and inference, implemented with loops and descriptive variable names, teach the tensor, explain how a modern CPU and GPU works (because many programmers still think a modern computer is just a much faster 6502), and then teach the tricks we use to make it fast.
      • groundzeros20152 hours ago
        I just assume that people who are going to do useful things in ML have basic foundation in math and science. If you don’t know what a derivative is what are we doing talking about multi-variable optimization.<p>And it’s not about gate-keeping it’s really about being able to reason about these concepts. What this looks like in programming is people memorizing a million clean code rules and not being able to write binary search.
        • fc417fc8021 hour ago
          There&#x27;s a wide gulf between knowing what a derivative is and proficiently working out the derivatives of arbitrary functions. The extent of understanding required for most applied ML is &quot;rate of change&quot;.
          • porridgeraisin1 hour ago
            Is it that wide though? For example, how do you explain why you cannot autograd through sampling (and thus you use either a reparameterization trick, or gumbel). Sure, instead of relying on differentiability, you can intuitively explain it &quot;the output changes only when you literally reach the next threshold, so all the way in between you don&#x27;t really get a good direction&quot;, but how far are you going to take this?<p>I agree with your general point, that we don&#x27;t need insane levels of math, but I would say a college level of calculus, linalg and probability is baseline.<p>A basic benchmark off the top of my head:<p>Being able to pick up, without stumbling on the fundamentals<p>- what LoRA is doing<p>- how a RBF-kernel SVM works<p>- why KL and reverse-KL are different<p>- why using mean squared error is equivalent to MLE on a gaussian<p>Not saying the four above pieces are all necessary, but that you should be able to learn them on demand without needing to revisit what a basis vector is.<p>&quot;Working out derivatives of arbitrary functions&quot; is school level.
            • fc417fc8021 hour ago
              Rate of change -&gt; it is flat -&gt; that is not a useful signal. I don&#x27;t see the issue?<p>We aren&#x27;t talking about doing cutting edge research, just educating people on the basics of how ML does what it does. I agree that the things you list should follow at some point in the sequence for any rigorous education. But it&#x27;s a question of at what point those things should come up and what the corresponding depth of education is.<p>For the initial introduction I think everything you listed is entirely out of scope. You don&#x27;t need any of that to get a basic MLP working using a for loop and naive gradient descent.
    • fc417fc8021 hour ago
      So you created a new account to blatantly plagiarize another comment from this same page? What&#x27;s even going on here?
  • axpy9066 hours ago
    Needs 2022 in title
  • jdw6410 hours ago
    Right now, all I know how to do is pull models from Hugging Face, but someday I want to build my own small LLM from scratch
    • max-amb9 hours ago
      If you want a written resource I have a blog post about the mathematics behind building a feed forward from scratch, <a href="https:&#x2F;&#x2F;max-amb.github.io&#x2F;blog&#x2F;the_maths_behind_the_mlp&#x2F;" rel="nofollow">https:&#x2F;&#x2F;max-amb.github.io&#x2F;blog&#x2F;the_maths_behind_the_mlp&#x2F;</a>. Kinda focuses on translation from individual components to matrix operations.
    • kflansburg10 hours ago
      If you aren&#x27;t already aware, Karpathy has several videos that could get you there in a few hours <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;@AndrejKarpathy" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;@AndrejKarpathy</a>
      • jdw6410 hours ago
        very thanks!
        • lancekey6 hours ago
          Also check out his nanochat repo. I used the repo, claude and shadeform to train my own mini model for about $300. Would have been less but I screwed up and let the cloud gpu rental run for a few hours even though the training run errored out.<p>Of course the model was dumber than GPT2 but still it was a great learning experience.
    • glouwbug10 hours ago
      It’s just linear algebra. Work your way from feed forward to CNN to RNN to LSTM to attention then maybe a small inference engine. Kaparthy’s llama2.c is only ~300 lines on the latter and it pragma simds so you don’t need fancy GPUs
  • hottrends48 minutes ago
    [flagged]
  • noosphr11 hours ago
    &gt;For example, getting good performance on a dataset with deep learning also involves a lot of guesswork. But, if your training loss is way lower than your test loss, you&#x27;re in the &quot;overfitting&quot; regime, and you&#x27;re wasting your time if you try to increase the capacity of your model.<p><a href="https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;1912.02292" rel="nofollow">https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;1912.02292</a>
    • appplication10 hours ago
      Generally, posting a link-only reply without further elaboration comes across as a bit rude. Are you providing support for the above point? Refuting it? You felt compelled to comment, a few words to indicate what you’re actually trying to say would go a long way.
      • noosphr10 hours ago
        &gt;We show that a variety of modern deep learning tasks exhibit a &quot;double-descent&quot; phenomenon where, as we increase model size, performance first gets worse and then gets better.
        • smallerize8 hours ago
          Does this mean that if your model is &quot;overfitting&quot;, the solution is to train for even more epochs?
          • noosphr1 hour ago
            Maybe. Just means that the conventional wisdom was wrong and substantially over training can be a good thing. No one I knew at the time suspected that, including the people who wrote the paper.
        • ForceBru9 hours ago
          Right, isn&#x27;t double descent one of the reasons why modern Extremely Large Language Models work at all? I think I heard somewhere that basically all today&#x27;s &quot;smart&quot; (reasoning, solving math problems, etc) LLMs are trained in the &quot;double descent&quot; territory (whatever this means, I&#x27;m not entirely sure).
          • mxwsn7 hours ago
            No, there are more training tokens than parameters in LLMs. They are in the classical first descent setting.
          • SiempreViernes9 hours ago
            No, double descent is a symptom of whatever it is that makes the deep models work at all. It&#x27;s just the name for something you see happen when it works. The reason it works has something to do with how all those extra dimensions work as a regularisation term in the fit.