<story><title>Writing Snake in 12 Lines of PyTorch</title><url>https://medium.com/artificialis/writing-snake-in-12-lines-of-pytorch-f7b21ce42a66</url></story><parent_chain></parent_chain><comment><author>Dzugaru</author><text>Implementing certain things in PyTorch can be fun. I&amp;#x27;ve recently started to make an economic game simulator (where you have players that can buy and sell items, do fighting etc.) and began to outline the design in the usual C#, but then, suddenly, thought - why not make the whole thing run on GPU and support millions of players with tens of millions sim steps per sec? This should make experiment cycles really fast - and that&amp;#x27;s what simulators are for!&lt;p&gt;If you don&amp;#x27;t want to program CUDA kernels yourself, what&amp;#x27;s the easiest tool for the job? PyTorch, of course. Mutable by default tensors, lots of library operations and generally a pleasure to use.&lt;p&gt;The programming is really interesting - you start to think in batches - every operation is a parallel operation, it&amp;#x27;s not 1 player&amp;#x2F;item doing something, it&amp;#x27;s a whole lot of them at once - and that&amp;#x27;s really fast.&lt;p&gt;I&amp;#x27;ve eventually did run into some problems - for example, ragged&amp;#x2F;sparse tensors support is not designed for this at all, and since I have variable number of items per player - this is a problem. Also, producing something like logs inside tensors is challenging - reallocation is very expensive and must be done in batches too. There are some other interesting things like launching several operations &amp;#x2F; CUDA kernels at once.</text></comment>
<story><title>Writing Snake in 12 Lines of PyTorch</title><url>https://medium.com/artificialis/writing-snake-in-12-lines-of-pytorch-f7b21ce42a66</url></story><parent_chain></parent_chain><comment><author>alberth</author><text>Is writing X in Y lines of code having any real meaning? I&amp;#x27;m not trying to be negative, just genuinely asking.&lt;p&gt;For example, in &lt;i&gt;1-line-of-code&lt;/i&gt; I can write &amp;quot;hello world&amp;quot;. This hello world is physically lighting up individual pixels on my display. It&amp;#x27;s rendering the letters to be the shape &amp;quot;hello world&amp;quot; should be. It has antialiasing applied. All in 1 line of code!!!</text></comment>