Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
clebert committed Oct 19, 2023
1 parent 96b1b5c commit 2e71144
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/attention.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/chat.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/chat_args.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/checkpoint.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/converter_args.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/ffn.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/generator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/generator_args.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/sampler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/tokenizer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/transformer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn init(

errdefer output_buffer.deinit();

return Self{
return .{
.allocator = allocator,
.checkpoint = checkpoint,
.sequence_length = sequence_length,
Expand Down

0 comments on commit 2e71144

Please sign in to comment.