From 2e71144b97852941a55e06bfe6883d84112dc2cc Mon Sep 17 00:00:00 2001 From: Clemens Akens Date: Thu, 19 Oct 2023 22:36:30 +0200 Subject: [PATCH] Minor refactoring --- README.md | 2 +- src/attention.zig | 2 +- src/chat.zig | 2 +- src/chat_args.zig | 2 +- src/checkpoint.zig | 4 ++-- src/converter_args.zig | 2 +- src/ffn.zig | 2 +- src/generator.zig | 2 +- src/generator_args.zig | 2 +- src/sampler.zig | 2 +- src/tokenizer.zig | 2 +- src/transformer.zig | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6d6b5ec..cae8cfc 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Lily wanted to play with the ball, but it was too high up in the sky. She tried Lily found a stick and tried to hit the ball. But the stick was too short. She tried again and again, but she couldn't reach it. She felt sad. Suddenly, a kind man came by and saw Lily. He asked her what was wrong. Lily told him about the ball. The man smiled and said, "I have a useful idea!" He took out a long stick and used it to knock the ball down. Lily was so happy! She thanked the man and they played together in the sunshine. -achieved: 712.903 tok/s +achieved: 726.974 tok/s ``` ## Run Llama 2 from Hugging Face diff --git a/src/attention.zig b/src/attention.zig index 32cbc26..43c7df3 100644 --- a/src/attention.zig +++ b/src/attention.zig @@ -53,7 +53,7 @@ pub fn init(allocator: std.mem.Allocator, checkpoint: Checkpoint, sequence_lengt errdefer allocator.free(scores); - return Self{ + return .{ .allocator = allocator, .checkpoint = checkpoint, .head_size = head_size, diff --git a/src/chat.zig b/src/chat.zig index 87923b9..f7290e5 100644 --- a/src/chat.zig +++ b/src/chat.zig @@ -28,7 +28,7 @@ pub fn init(allocator: std.mem.Allocator, args: ChatArgs) !Self { errdefer sampler.deinit(); - return Self{ + return .{ .allocator = allocator, .transformer = transformer, .tokenizer = tokenizer, diff --git a/src/chat_args.zig b/src/chat_args.zig index 5441795..040bda4 100644 --- a/src/chat_args.zig +++ b/src/chat_args.zig @@ -77,7 +77,7 @@ pub fn init(allocator: std.mem.Allocator) !Self { try help(1); } - return Self{ + return .{ .arg_iterator = arg_iterator, .model_path = model_path, .temperature = @max(@min(temperature orelse 1, 1), 0), diff --git a/src/checkpoint.zig b/src/checkpoint.zig index c8e0087..0781c77 100644 --- a/src/checkpoint.zig +++ b/src/checkpoint.zig @@ -227,7 +227,7 @@ fn readV1(allocator: std.mem.Allocator, file: std.fs.File) !Self { try output_matrix.read(file); } - return Self{ + return .{ .allocator = allocator, .embedding_size = embedding_size, .ffn_hidden_size = ffn_hidden_size, @@ -375,7 +375,7 @@ fn readLegacy(allocator: std.mem.Allocator, file: std.fs.File) !Self { try output_matrix.read(file); } - return Self{ + return .{ .allocator = allocator, .embedding_size = embedding_size, .ffn_hidden_size = ffn_hidden_size, diff --git a/src/converter_args.zig b/src/converter_args.zig index 41f3d7b..c086b7c 100644 --- a/src/converter_args.zig +++ b/src/converter_args.zig @@ -18,7 +18,7 @@ pub fn init(allocator: std.mem.Allocator) !Self { try help(if (std.mem.eql(u8, arg, "--help")) 0 else 1); } - return Self{ .arg_iterator = arg_iterator, .model_path = model_path }; + return .{ .arg_iterator = arg_iterator, .model_path = model_path }; } pub fn deinit(self: *Self) void { diff --git a/src/ffn.zig b/src/ffn.zig index 711740a..936c137 100644 --- a/src/ffn.zig +++ b/src/ffn.zig @@ -28,7 +28,7 @@ pub fn init(allocator: std.mem.Allocator, checkpoint: Checkpoint) !Self { errdefer output_buffer.deinit(); - return Self{ + return .{ .allocator = allocator, .checkpoint = checkpoint, .input_buffer = input_buffer, diff --git a/src/generator.zig b/src/generator.zig index dd07e63..1dc62fd 100644 --- a/src/generator.zig +++ b/src/generator.zig @@ -30,7 +30,7 @@ pub fn init(allocator: std.mem.Allocator, args: GeneratorArgs) !Self { const prompt_tokens = try tokenizer.encode(allocator, args.prompt); - return Self{ + return .{ .allocator = allocator, .transformer = transformer, .tokenizer = tokenizer, diff --git a/src/generator_args.zig b/src/generator_args.zig index 20bfe1d..b95fe05 100644 --- a/src/generator_args.zig +++ b/src/generator_args.zig @@ -68,7 +68,7 @@ pub fn init(allocator: std.mem.Allocator) !Self { try help(1); } - return Self{ + return .{ .arg_iterator = arg_iterator, .model_path = model_path, .temperature = @max(@min(temperature orelse 1, 1), 0), diff --git a/src/sampler.zig b/src/sampler.zig index 9dfa5c2..6001921 100644 --- a/src/sampler.zig +++ b/src/sampler.zig @@ -14,7 +14,7 @@ pub fn init(allocator: std.mem.Allocator, args: anytype, vocab_size: usize) !Sel const probability_index_pairs_buffer = try allocator.alloc(ProbabilityIndexPair, vocab_size); - return Self{ + return .{ .allocator = allocator, .probability_index_pairs_buffer = probability_index_pairs_buffer, .temperature = args.temperature, diff --git a/src/tokenizer.zig b/src/tokenizer.zig index c742635..055161a 100644 --- a/src/tokenizer.zig +++ b/src/tokenizer.zig @@ -45,7 +45,7 @@ pub fn init(allocator: std.mem.Allocator, model_path: []const u8, vocab_size: us const sorted_vocab = try sortVocab(allocator, vocab); - return Self{ + return .{ .allocator = allocator, .max_word_length = max_word_length, .vocab = vocab, diff --git a/src/transformer.zig b/src/transformer.zig index b86fc96..53c9554 100644 --- a/src/transformer.zig +++ b/src/transformer.zig @@ -44,7 +44,7 @@ pub fn init( errdefer output_buffer.deinit(); - return Self{ + return .{ .allocator = allocator, .checkpoint = checkpoint, .sequence_length = sequence_length,