35 pointsby eatonphil4 hours ago7 comments
  • hastegan hour ago
    I just recently watched some (not all) of this video "coding a machine learning library in c from scratch" and seems like he's going through a similar process in this blog as this video. I would recommend watching the video to get an idea of what the fundamentals of a ML library look like. From someone who has recently been getting interested in actually writing ML code and trying to make sense of it myself (from the perspective of just a typical backend engineer) it was very interesting to see. Previously my experience with ML libs (PyTorch specific) was writing my own Mini-GPT and training it on a small dataset using my own GPU (5090). Cool to see the behind the scenes and took away some o the handwaveyness... https://www.youtube.com/watch?v=hL_n_GljC0I
  • srean3 hours ago
    If one wants to add the capability to reason about shape and shape compatibility, Barry Jay's FiSh would be an interesting detour.

    https://web.archive.org/web/20111015133833/http://www-staff....

    This was used in his shape aware language FiSh, for dealing with multidimensional arrays. Shape compatibilities were statically type checked, if I recall correctly. Shapes were also used to optimize the loops.

    [Programming in FISh] https://link.springer.com/article/10.1007/s100090050037

    [Towards Dynamic Shaping] https://www.researchgate.net/publication/265975794_Towards_D...

    • zserge3 hours ago
      I wish we used something else but Python as the default ML language, so that some advanced type system would work for us to ensure tensor shapes and compatibility.
      • ux2664782 hours ago
        Haskell is actually really good for that. Hasktorch[1] is high quality, batteries included, and leverages Haskell's GADTs for some cute stuff like gradual tensor shape checking. There's also just a grain to Haskell that feels really good for the machine learning domain. It doesn't just alleviate whole classes of bugs and a lot of annoying background noise reasoning, but it's also a much more natural-feeling expression.

        The "gotcha" is that Haskell is heavy duty machinery, and getting up to speed with it if your background lacks solid type-theory can be really daunting. For that reason alone, it could never be the default. Sometimes I like to think about how much of a disservice academia has done to itself by training mathematicians without giving them the foundational knowledge they need to utilize the nuclear-grade tooling they themselves have the most potential to benefit from. For a number theorist? Sure makes sense. But the fact that machine learning courses don't have rigorous undergraduate prerequisites in learning the foundation of computation is pure absurdity.

        [1] - http://hasktorch.org/

      • bssrdf2 hours ago
        I found [ggml] is really easy, educational and fun to use. It is written in C and the backbone for llama.cpp.

        [ggml]https://github.com/ggml-org/ggml

      • churchsub12 hours ago
        Here's a Python library for static type checking of tensor shapes: https://pypie.dev/
      • srean3 hours ago
        Honestly, I quite like Python most of the time. The times when I don't, argghh type errors.

        The worst I have had in a while is when I was dealing with a sparse array data type and getting some processing done in a C function to speed things up.

        Infuriatingly enough, the index type used to change after initialising the array. It would check if Int32 could accomodate the size of the array. If it could it would downgrade to Int32 at runtime. My C counterpart had no clue.

        That was so not fun to debug because the errors were intermittent (depending on the fill factor of the sparse array)

      • weiserwx3 hours ago
        [dead]
  • srean3 hours ago
    > A tensor is nothing but a flat array of numbers, plus some metadata telling you how to interpret those numbers as a multi-dimensional object.

    Erm... many would disagree. I think what he means is just a multidimensional array.

    • zserge3 hours ago
      Not in a general mathematical sense, of course. Rather carthesian tensors. Seems like for most libraries it's `numpy.ndarray`: https://docs.tinygrad.org/tensor/ or https://docs.pytorch.org/docs/main/tensors.html
      • srean3 hours ago
        To add to the confusion, Mathematicians and Physicists often disagree on what that word means. A Physicist's tensor is often a mathematicians tensor field.

        An appropriate tensor can certainly be represented by a multidimensional array but not all multidimensional arrays are tensors. It depends on how that multidimensional array participates with others.

        For example, (lat, long) is not a 2d vector although it can be represented as a 2 dimensional array.

  • reerdna2 hours ago
    Cool, but I find rather than just shapes and indexes, tensors with labels are much easier to use and reason about. E.g.:

      {
          {user:bob, movie:"Heat"}:0.1,
          {user:alice, movie:"Frozen"}:0.9,
          {user:carol, movie:"Top Gun"}:0.3,
      }
    
    https://docs.vespa.ai/en/ranking/tensor-user-guide.html
  • nathan_compton13 minutes ago
    I know there are different contexts, but a tensor is not a collection of numbers, in a mathematical sense. A vector is not a list of numbers. Such collections of numbers are representations of objects with very specific kinds of properties under coordinate transformations.

    I think it genuinely damages people's ability to digest the mathematics to tell them first and foremost that these objects are collections of numbers.

  • terminalbraid16 minutes ago
    > A tensor is nothing but a flat array of numbers

    I'm so very, very tired of tech coopting rigorous mathematical terms.

    • mamcx13 minutes ago
      I read it as "tensors in programming*.

      This also happens to "numbers", "integers" and such, because in the computer universe don't exist out math, only a subset(?) variation(?) of it

  • khalic2 hours ago
    Why does does the diagram say tensors are 3D?
    • zserge2 hours ago
      I guess I miscommunicated it. I meant I'd call everything a tensor but for some smaller dimensions we have specific names. Of course, 1D can still be a tensor and so is 6D or nD.
      • khalican hour ago
        Got it, thx!
        • zserge22 minutes ago
          I suppose one of a few examples when a picture is totally not worth a thousand words, if a picture is made by me
          • khalic3 minutes ago
            hahaha don’t sweat it, we all visualise things differently