[{"data":1,"prerenderedAt":25},["ShallowReactive",2],{"chapter:teenygrad\u002Fgetting-started\u002Ffirst-model.json":3},{"project":4,"route":5,"title":6,"titleHtml":6,"navTitle":6,"part":7,"sourcePath":8,"editUrl":9,"html":10,"toc":11,"hasMermaid":16,"prev":17,"next":21},"teenygrad","\u002Fteenygrad\u002Fgetting-started\u002Ffirst-model","Your First Model","Getting Started","getting-started\u002Ffirst-model.md","https:\u002F\u002Fgithub.com\u002Fteenygrad\u002Fteenygrad\u002Fedit\u002Fmain\u002Fbooks\u002Fteenygrad\u002Fsrc\u002Fgetting-started\u002Ffirst-model.md","\u003Cp>The canonical end-to-end example in the workspace today is\n\u003Ca href=\"\u002Fapi\u002Fteenygrad\u002Fteenygrad\u002Fteeny_vision\u002F\">\u003Ccode>teeny-vision\u003C\u002Fcode>\u003C\u002Fa>’s LeNet-5 over MNIST:\u003C\u002Fp>\n\u003Cpre data-lang=\"rust\" class=\"shiki teeny-datasheet\" style=\"background-color:#16181a;color:#e6e8e3\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#FF5F9E\">use\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> teeny_vision\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">::\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">mnist\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">::\u003C\u002Fspan>\u003Cspan style=\"color:#E6E8E3\">mnist_lenet5\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#FF5F9E\">let\u003C\u002Fspan>\u003Cspan style=\"color:#E6E8E3\"> model \u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">=\u003C\u002Fspan>\u003Cspan style=\"color:#7FB6D9\"> mnist_lenet5\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">::&#x3C;\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">f32\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">>();\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>That model is used in two different ways elsewhere in the workspace, both worth reading as\nreference implementations:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>Training\u002Finference example\u003C\u002Fstrong>: \u003Ccode>models\u002Fteeny-vision\u002Fexamples\u002Fmnist.rs\u003C\u002Fcode> — a full,\nrunnable example (\u003Ccode>cargo run --example mnist\u003C\u002Fcode>, with \u003Ccode>TEENYC_PATH\u003C\u002Fcode> set — see\n\u003Ca href=\"\u002Fteenygrad\u002Fgetting-started\u002Finstallation\">Installation\u003C\u002Fa>).\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Ahead-of-time kernel compilation\u003C\u002Fstrong>: \u003Ccode>utilities\u002Fteeny-cli\u002Fsrc\u002Fmain.rs\u003C\u002Fcode> — traces the model with\na symbolic input and AOT-compiles its kernels via\n\u003Ca href=\"\u002Fapi\u002Fteenygrad\u002Fteenygrad\u002Fteeny_cli\u002F\">\u003Ccode>teeny_cli::aot_compile\u003C\u002Fcode>\u003C\u002Fa>.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2 id=\"the-shape-of-a-model\">The shape of a model\u003C\u002Fh2>\n\u003Cp>Models are built from \u003Ccode>teeny-core\u003C\u002Fcode>’s \u003Ca href=\"\u002Fapi\u002Fteenygrad\u002Fteenygrad\u002Fteeny_core\u002Fnn\u002F\">\u003Ccode>nn\u003C\u002Fcode>\u003C\u002Fa> layer\ntypes, implementing the \u003Ccode>Layer\u003C\u002Fcode> trait. A traced model produces a symbolic computational graph\n(\u003Ccode>SymTensor\u003C\u002Fcode> in, \u003Ccode>Graph\u003C\u002Fcode> out) — see \u003Ca href=\"\u002Fteenygrad\u002Fcore-concepts\u002Ftensors-and-graph\">Tensors &amp; the Computational Graph\u003C\u002Fa>\nand \u003Ca href=\"\u002Fteenygrad\u002Fcore-concepts\u002Fcompilation-flow\">Compilation Flow\u003C\u002Fa> for what happens to that graph next.\u003C\u002Fp>\n\u003Cblockquote>\n\u003Cp>\u003Cstrong>TODO\u003C\u002Fstrong>: walk through building a small model from scratch (not just pointing at the existing\nLeNet-5 example) once the \u003Ccode>nn\u003C\u002Fcode> layer API stabilizes enough to commit to in a book.\u003C\u002Fp>\n\u003C\u002Fblockquote>\n",[12],{"id":13,"text":14,"level":15},"the-shape-of-a-model","The shape of a model",2,false,{"title":18,"titleHtml":19,"route":20},"Installation & Toolchain","Installation &amp; Toolchain","\u002Fteenygrad\u002Fgetting-started\u002Finstallation",{"title":22,"titleHtml":23,"route":24},"Tensors & the Computational Graph","Tensors &amp; the Computational Graph","\u002Fteenygrad\u002Fcore-concepts\u002Ftensors-and-graph",1786271828999]