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; +} 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); } } } 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 => {}, } 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 = {} }; 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 { diff --git a/zml/tools/tracer.zig b/zml/tools/tracer.zig index 06bcd6fa..3d0c1b31 100644 --- a/zml/tools/tracer.zig +++ b/zml/tools/tracer.zig @@ -1,9 +1,10 @@ const builtin = @import("builtin"); + 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, }; @@ -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;