Skip to content

Commit

Permalink
update zig
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomsik committed Dec 10, 2023
1 parent dc383ee commit e723d1c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn build(b: *std.Build) !void {
if (target.getOsTag() == .macos) {
lib.defineCMacroRaw("GGML_USE_METAL");
lib.defineCMacroRaw("GGML_METAL_NDEBUG");
lib.addCSourceFiles(&.{"deps/ggml/src/ggml-metal.m"}, &.{"-std=c11"});
lib.addCSourceFiles(.{ .files = &.{"deps/ggml/src/ggml-metal.m"}, .flags = &.{"-std=c11"} });
lib.linkFramework("Foundation");
lib.linkFramework("Metal");
lib.linkFramework("MetalKit");
Expand Down
2 changes: 1 addition & 1 deletion deps/napigen
2 changes: 1 addition & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn napigenWrite(js: *napigen.JsContext, value: anytype) !napigen.napi_value
return switch (@TypeOf(value)) {
// alloc a pointer and write the value to it
safetensors.SafeTensors, ggml.ggml_cgraph, ggml.ggml_cplan => {
var ptr = napigen.allocator.create(@TypeOf(value)) catch unreachable;
const ptr = napigen.allocator.create(@TypeOf(value)) catch unreachable;
ptr.* = value;
return js.write(ptr);
},
Expand Down
2 changes: 1 addition & 1 deletion src/safetensors.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn safetensors_open(path: []const u8) !SafeTensors {

var reader = file.reader();
const header_start = @sizeOf(u64);
const header_size: usize = @intCast(try reader.readIntLittle(u64));
const header_size: usize = @intCast(try reader.readInt(u64, .little));

return .{
.file = file,
Expand Down
6 changes: 3 additions & 3 deletions src/sampling.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn sample_typical(tensor: *ggml.ggml_tensor, temperature: f32, tau: f32) !u3
for (list.items) |it| entropy += -it.prob * @log(it.prob);

// compute shifted_scores & sort
for (list.items) |*it| it.score = @fabs(-@log(it.prob) - entropy);
for (list.items) |*it| it.score = @abs(-@log(it.prob) - entropy);
sort_by(list.items, .score, std.sort.desc(f32));

if (find_cutoff(list.items, tau)) |i| {
Expand Down Expand Up @@ -70,8 +70,8 @@ pub fn sample_top_k_top_p(tensor: *ggml.ggml_tensor, top_k: u32, top_p: f32, tem

fn prepare_candidates(tensor: *ggml.ggml_tensor) !std.ArrayList(Candidate) {
var ptr = ggml.ggml_get_data_f32(tensor);
var probs = ptr[0..@intCast(tensor.ne[0])];
var items = try root.allocator.alloc(Candidate, probs.len);
const probs = ptr[0..@intCast(tensor.ne[0])];
const items = try root.allocator.alloc(Candidate, probs.len);

if (probs.len == 0) {
return error.InvalidInput;
Expand Down

0 comments on commit e723d1c

Please sign in to comment.