From 6540becb0501e5baabaf60941b915b0fee822969 Mon Sep 17 00:00:00 2001 From: Corentin Godeau Date: Fri, 20 Jun 2025 12:35:08 +0000 Subject: [PATCH 1/7] zml/exe: don't wait for event Don't forget to delete them --- zml/exe.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zml/exe.zig b/zml/exe.zig index 0923f17c..d5c26795 100644 --- a/zml/exe.zig +++ b/zml/exe.zig @@ -251,7 +251,7 @@ pub const BaseExe = struct { for (events[0..sharding.num_partitions]) |e| { if (e) |ev| { - ev.await_(self.platform.pjrt_api) catch unreachable; + ev.deinit(self.platform.pjrt_api); } } } From 222e3d04c133ae81d38498386bd65bec5eace292 Mon Sep 17 00:00:00 2001 From: Corentin Godeau Date: Fri, 20 Jun 2025 12:35:31 +0000 Subject: [PATCH 2/7] zml/pjrtx: remove async blocking call to execute --- zml/pjrtx.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zml/pjrtx.zig b/zml/pjrtx.zig index 1795efc3..9e3143d6 100644 --- a/zml/pjrtx.zig +++ b/zml/pjrtx.zig @@ -272,14 +272,14 @@ pub const LoadedExecutable = opaque { }; pub fn execute(self: *const LoadedExecutable, api: *const Api, args: ExecuteArgs) ExecuteError!void { - try asynk.callBlocking(pjrt.LoadedExecutable.execute, .{ self.inner(), api, pjrt.LoadedExecutable.ExecuteArgs{ + try self.inner().execute(api, pjrt.LoadedExecutable.ExecuteArgs{ .num_args = args.num_args, .arguments = @ptrCast(args.arguments), .results = @ptrCast(args.results), .events = @ptrCast(args.events), .non_donatable_input_indices = args.non_donatable_input_indices, .context = args.context, - } }); + }); } pub fn getExecutable(self: *LoadedExecutable, api: *const Api) ApiError!*Executable { From 2224423922552d7859900199efd0c46457de6a23 Mon Sep 17 00:00:00 2001 From: Corentin Godeau Date: Thu, 26 Jun 2025 12:37:28 +0000 Subject: [PATCH 3/7] zml/module.zig: disable gemm autotuning on ROCm This is taking way too much time for llmd --- zml/module.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/zml/module.zig b/zml/module.zig index f031e815..0c2f746c 100644 --- a/zml/module.zig +++ b/zml/module.zig @@ -899,6 +899,7 @@ fn compileModuleToPjrtExecutable(arena: std.mem.Allocator, platform: Platform, m // Use lld from libllvm instead of invoking the ld.lld binary. // This saves us from having to sandbox it. setFlag(&options, "xla_gpu_use_inprocess_lld", true); + setFlag(&options, "xla_gpu_autotune_level", 0); }, else => {}, } From ace0bf4eaa0642c5af0f8cb3c8d7dc65ed6c5b54 Mon Sep 17 00:00:00 2001 From: Corentin Godeau Date: Thu, 26 Jun 2025 12:55:39 +0000 Subject: [PATCH 4/7] zml/tools/tracer.zig: make FakeTracer api compatible with CudaTracer --- zml/tools/tracer.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zml/tools/tracer.zig b/zml/tools/tracer.zig index 06bcd6fa..7efe748a 100644 --- a/zml/tools/tracer.zig +++ b/zml/tools/tracer.zig @@ -1,4 +1,5 @@ const builtin = @import("builtin"); + const c = @import("c"); pub const Tracer = switch (builtin.os.tag) { @@ -83,6 +84,10 @@ const FakeTracer = struct { return .{}; } + pub fn deinit(self: *const FakeTracer) void { + _ = self; + } + pub fn event(self: *const FakeTracer, message: [:0]const u8) void { _ = self; _ = message; From fea85cf7f06343fb9c1a1ceacb8c4121a3aae507 Mon Sep 17 00:00:00 2001 From: Corentin Godeau Date: Wed, 9 Jul 2025 11:34:29 +0000 Subject: [PATCH 5/7] stdx/math: added cdiv function --- stdx/math.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdx/math.zig b/stdx/math.zig index da0bec79..1e1e1318 100644 --- a/stdx/math.zig +++ b/stdx/math.zig @@ -21,3 +21,7 @@ pub inline fn roundeven(x: anytype) @TypeOf(x) { extern fn @"llvm.roundeven"(@TypeOf(x)) @TypeOf(x); }.@"llvm.roundeven"(x); } + +pub fn cdiv(numerator: anytype, denominator: anytype) @TypeOf(numerator) { + return (numerator + denominator - 1) / denominator; +} From 7c58136bbd846dc1bc5dc3edbc22a4f94c232267 Mon Sep 17 00:00:00 2001 From: Corentin Godeau Date: Fri, 11 Jul 2025 15:36:19 +0000 Subject: [PATCH 6/7] zml/nn: correctly parse RopeOpts.Scaling from JSON --- zml/nn.zig | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/zml/nn.zig b/zml/nn.zig index ffdb7a9c..adc06237 100644 --- a/zml/nn.zig +++ b/zml/nn.zig @@ -175,17 +175,23 @@ pub const RopeOpts = struct { /// Read a Rope scaling config from HF config.json format. pub fn jsonParse(allocator: std.mem.Allocator, source: anytype, options: std.json.ParseOptions) !Scaling { - const content = try std.json.Value.jsonParse(allocator, source, options); - if (content == .null) return .default; + return jsonParseFromValue( + allocator, + try std.json.innerParse(std.json.Value, allocator, source, options), + options, + ); + } - if (content != .object) return error.InvalidEnumTag; + pub fn jsonParseFromValue(allocator: std.mem.Allocator, source: std.json.Value, options: std.json.ParseOptions) std.json.ParseFromValueError!Scaling { + if (source == .null) return .default; - const obj = content.object; + if (source != .object) return error.InvalidEnumTag; + + const obj = source.object; const impl = obj.get("rope_type") orelse return error.MissingField; if (impl != .string) return error.InvalidEnumTag; if (std.mem.eql(u8, impl.string, "llama3")) { - // Note: leaky is fine here cause Llama3 struct don't need to allocate memory. - return .{ .llama3 = try std.json.parseFromValueLeaky(Llama3, undefined, content, .{ .ignore_unknown_fields = true }) }; + return .{ .llama3 = try std.json.innerParseFromValue(Llama3, allocator, source, options) }; } else { log.warn("Unsupported Rope implementation: {s}, will use the default one which will produce altered results", .{impl.string}); return .{ .default = {} }; From 328fd9b3cd046c1ab3359e7b9716d8f867985fb5 Mon Sep 17 00:00:00 2001 From: Corentin Godeau Date: Wed, 16 Jul 2025 13:51:24 +0000 Subject: [PATCH 7/7] zml/tools: temporarily disable CudaTracer for universal binaries --- zml/tools/tracer.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zml/tools/tracer.zig b/zml/tools/tracer.zig index 7efe748a..3d0c1b31 100644 --- a/zml/tools/tracer.zig +++ b/zml/tools/tracer.zig @@ -4,7 +4,7 @@ const c = @import("c"); pub const Tracer = switch (builtin.os.tag) { .macos => MacOsTracer, - .linux => if (@hasDecl(c, "ZML_RUNTIME_CUDA")) CudaTracer else FakeTracer, + .linux => FakeTracer, else => FakeTracer, };