Update docs and examples to showcase the new async runtime with coroutines and cross‑thread signaling.

This commit is contained in:
Foke Singh 2023-08-03 11:35:24 +00:00
parent bcde3962ce
commit 726a2d0691
6 changed files with 16 additions and 16 deletions

View File

@ -101,7 +101,7 @@ const std = @import("std");
const zml = @import("zml");
const asynk = @import("async");
// shortcut to the async_ function in the asynk module
// shortcut to the asyncc function in the asynk module
const asyncc = asynk.asyncc;
```
@ -263,11 +263,11 @@ 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_();
const compiled = try compilation.awaitt();
```
Compiling is happening in the background via the `async_` function. We call
`async_` with the `zml.compileModel` function and its arguments
Compiling is happening in the background via the `asyncc` function. We call
`asyncc` with the `zml.compileModel` function and its arguments
separately. The arguments themselves are basically the shapes of the weights in
the BufferStore, the `.forward` function name in order to compile
`Layer.forward`, the shape of the input tensor(s), and the platform for which to
@ -494,7 +494,7 @@ pub fn asyncMain() !void {
defer zml.aio.unloadBuffers(&model_weights); // for good practice
// Wait for compilation to finish
const compiled = try compilation.await_();
const compiled = try compilation.awaitt();
// pass the model weights to the compiled module to create an executable
// module

View File

@ -63,7 +63,7 @@ pub fn asyncMain() !void {
var compilation = try asynk.asyncc(zml.module.compileModel, .{ allocator, Benchmark.forward, Benchmark{}, .{ a_shape, b_shape }, platform });
// Wait for compilation to finish
const compiled = try compilation.await_();
const compiled = try compilation.awaitt();
const compilation_elapsed = timer.lap() / std.time.ns_per_ms;
std.debug.print("-" ** 160 ++ "\n\n", .{});
std.debug.print("✅ Compiled Benchmark model in {d} milliseconds! \n", .{compilation_elapsed});

View File

@ -217,9 +217,9 @@ pub fn asyncMain() !void {
defer zml.aio.unloadBuffers(&llama_weights);
log.info("\tLoaded weights in {d}ms", .{start.read() / std.time.ns_per_ms});
var llama_module_prefill = try (try fut_mod_prefill.await_()).prepare(allocator, llama_weights);
var llama_module_prefill = try (try fut_mod_prefill.awaitt()).prepare(allocator, llama_weights);
defer llama_module_prefill.deinit();
var llama_module = try (try fut_mod.await_()).prepare(allocator, llama_weights);
var llama_module = try (try fut_mod.awaitt()).prepare(allocator, llama_weights);
defer llama_module.deinit();
log.info("\tCompiled model in {d}ms", .{start.read() / std.time.ns_per_ms});

View File

@ -6,6 +6,11 @@ const show_mlir = true;
const log = std.log.scoped(.mnist);
pub const std_options: std.Options = .{
.logFn = asynk.logFn,
.log_level = .info,
};
/// Model definition
const Mnist = struct {
fc1: Layer,
@ -78,7 +83,7 @@ pub fn asyncMain() !void {
defer zml.aio.unloadBuffers(&model_weights);
// Wait for end of compilation and end of weights loading.
const compiled_mnist = try compilation.wait();
const compiled_mnist = try compilation.awaitt();
log.info("✅ Compiled model in {d}ms", .{start_time.read() / std.time.ns_per_ms});
var mnist = try compiled_mnist.prepare(allocator, model_weights);
@ -222,8 +227,3 @@ const digits = [_][]const u8{
\\ | ##### |
,
};
pub const std_options = .{
.logFn = asynk.logFn,
.log_level = .info,
};

View File

@ -71,7 +71,7 @@ pub fn asyncMain() !void {
defer zml.aio.unloadBuffers(&model_weights); // for good practice
// Wait for compilation to finish
const compiled = try compilation.await_();
const compiled = try compilation.awaitt();
// pass the model weights to the compiled module to create an executable module
var executable = try compiled.prepare(arena, model_weights);

View File

@ -2,7 +2,7 @@
"build_options": [
{
"name": "cmd",
"value": "bazel run @zml//zml:completion"
"value": "bazel run @zml//:completion"
}
]
}