From 848d9c67d6ccd7f9ede700d307829c895bfd3d49 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 17 Sep 2024 14:31:10 +0000 Subject: [PATCH] Update GitHub Pages --- README.md | 1 + sources.tar | Bin 614400 -> 614400 bytes tutorials/write_first_model/index.html | 47 ++++++++++++++++--------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index da95b22..6daa1cd 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,4 @@ Tue Sep 17 08:21:47 UTC 2024 Tue Sep 17 08:38:09 UTC 2024 Tue Sep 17 08:46:50 UTC 2024 Tue Sep 17 10:57:15 UTC 2024 +Tue Sep 17 14:31:10 UTC 2024 diff --git a/sources.tar b/sources.tar index 74ce87ab5de62e69da2caa88af572f9f2ba93c42..32eadbd9382a413d33b574d4b117e596e0ec0f54 100755 GIT binary patch delta 982 zcmY+DuS*0$6o7s1ox95g1vw58L6GAR1n13rGmF7sHW|b}K*eD6AGjhSJV6kX7)^!? zhN)MK2D3qoCWAptdZ0URHf;L#d%tHm?hnWP%ZoWev}mUcTIbxCAUHev6YF=vn(Zq9Y*pYi%J-M?F8t6I7PN1|1SmDYSe8ju4@Qz z2QpBL$Z)itK;9HtMzu!Ma+4sBYHeqY8KJi^;3$&~wa8Q5R)F_R$^;=R`pl%Qh#hIb z?<}1LnMy0{w&YqZBC0DqgZtLxYX`WWkz@UZDegHyFPB+G#BntN2Dz*%Vv|f|CzlgN zgh_voxu7EJC#UsyQvts6M(fV#-k^{Lwa8hD)?y*u6k&ae0kDvcB8NuNW+R}Zc%}jN zinL{RUUMB4jdS#gby~=-=AsI9Z!d*p2}-TkqVZZ>a&%eQcrKGS7F+I>($j!!EA4B& NOmi_?9WRwXYrjv(*p&bP delta 982 zcmY+Dp-Ti&5XNuZJ9n203UVBB2!b4kAh`49y|)+)W|Kku15^w~|A8wa!U%$x#Av#3 z!SL!8qrq$tqsd?plWuU|%!W<~2oZ>7wS6mlQz~a?hlQDSgzu@QNbVm63e%K!`E5t^ua27VW0tP$08j_(xmMpU~=V@6mOvEVe}Em4uDI#z&>gmZ<^3i?X8 zBgi@{1%DDf4Z=bk_S$?aDk57uynso&`Z@t7^L#45*ve0I+D~~w5ZSnz0Hc)G1=&JP zWiRD3L4+#bQ_3jFcq1Xc(?)cMvNyeB@ diff --git a/tutorials/write_first_model/index.html b/tutorials/write_first_model/index.html index 58e1cac..b4dab89 100644 --- a/tutorials/write_first_model/index.html +++ b/tutorials/write_first_model/index.html @@ -227,12 +227,15 @@

// Start compiling. This uses the inferred shapes from the BufferStore. // The shape of the input tensor, we have to pass in manually. -var compilation = try async_(zml.compileModel, .{ allocator, model_shapes, .forward, .{input_shape}, platform }); +var compilation = try async_( + zml.compileModel, + .{ allocator, model_shapes, .forward, .{input_shape}, platform }, +); // Produce a bufferized weights struct from the fake BufferStore. // This is like the inferred shapes, but with actual values. // We will need to send those to the computation device later. -const model_weights = try zml.aio.loadBuffers(Layer, .{}, bs, arena, platform); +var model_weights = try zml.aio.loadBuffers(Layer, .{}, bs, arena, platform); defer zml.aio.unloadBuffers(&model_weights); // for good practice // Wait for compilation to finish @@ -243,11 +246,15 @@

defer executable.deinit();

Calling / running the Model

The executable can now be invoked with an input of our choice.

To create the input, we directly use zml.Buffer by calling zml.Buffer.fromArray(). It's important to note that Buffers reside in accelerator (or device) memory, which is precisely where the input needs to be for the executable to process it on the device.

For clarity, let's recap the distinction: HostBuffers are located in standard host memory, which is accessible by the CPU. When we initialized the weights, we used HostBuffers to set up the BufferStore. This is because the BufferStore typically loads weights from disk into HostBuffers, and then converts them into Buffers when we call loadBuffers().

However, for inputs, we bypass the BufferStore and create Buffers directly in device memory.

// prepare an input buffer
-// Here, we use zml.HostBuffer.fromSlice to show how you would create a HostBuffer 
-// with a specific shape from an array.
-// For situations where e.g. you have an [4]f16 array but need a .{2, 2} input shape.
+// Here, we use zml.HostBuffer.fromSlice to show how you would create a 
+// HostBuffer with a specific shape from an array.
+// For situations where e.g. you have an [4]f16 array but need a .{2, 2} input 
+// shape.
 var input = [3]f16{ 5.0, 5.0, 5.0 };
-var input_buffer = try zml.Buffer.from(platform, zml.HostBuffer.fromSlice(input_shape, &input));
+var input_buffer = try zml.Buffer.from(
+    platform,
+    zml.HostBuffer.fromSlice(input_shape, &input),
+);
 defer input_buffer.deinit();
 
 // call our executable module
@@ -354,33 +361,41 @@ 

Running it

With everything in place now, running the .buffers = buffers, }; - // A clone of our model, consisting of shapes. We only need shapes for compiling. - // We use the BufferStore to infer the shapes. + // A clone of our model, consisting of shapes. We only need shapes for + // compiling. We use the BufferStore to infer the shapes. const model_shapes = try zml.aio.populateModel(Layer, allocator, bs); // Start compiling. This uses the inferred shapes from the BufferStore. // The shape of the input tensor, we have to pass in manually. - var compilation = try async_(zml.compileModel, .{ allocator, model_shapes, .forward, .{input_shape}, platform }); + var compilation = try async_( + zml.compileModel, + .{ allocator, model_shapes, .forward, .{input_shape}, platform }, + ); // Produce a bufferized weights struct from the fake BufferStore. // This is like the inferred shapes, but with actual values. // We will need to send those to the computation device later. - const model_weights = try zml.aio.loadBuffers(Layer, .{}, bs, arena, platform); - defer zml.aio.unloadBuffers(&model_weights); + var model_weights = try zml.aio.loadBuffers(Layer, .{}, bs, arena, platform); + defer zml.aio.unloadBuffers(&model_weights); // for good practice // Wait for compilation to finish const compiled = try compilation.await_(); - // pass the model weights to the compiled module to create an executable module + // pass the model weights to the compiled module to create an executable + // module var executable = try compiled.prepare(arena, model_weights); defer executable.deinit(); // prepare an input buffer - // Here, we use zml.HostBuffer.fromSlice to show how you would create a HostBuffer - // with a specific shape from an array. - // For situations where e.g. you have an [4]f16 array but need a .{2, 2} input shape. + // Here, we use zml.HostBuffer.fromSlice to show how you would create a + // HostBuffer with a specific shape from an array. + // For situations where e.g. you have an [4]f16 array but need a .{2, 2} + // input shape. var input = [3]f16{ 5.0, 5.0, 5.0 }; - var input_buffer = try zml.Buffer.from(platform, zml.HostBuffer.fromSlice(input_shape, &input)); + var input_buffer = try zml.Buffer.from( + platform, + zml.HostBuffer.fromSlice(input_shape, &input), + ); defer input_buffer.deinit(); // call our executable module