Skip to content

Commit 4579af9

Browse files
foldlzjli-2019
andauthored
zig : update build.zig (abetlen#872)
* update * update readme * minimize the changes. --------- Co-authored-by: zjli2019 <[email protected]>
1 parent 8c3ffc2 commit 4579af9

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

README.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,43 @@ https://user-images.githubusercontent.com/1991296/224442907-7693d4be-acaa-4e01-8
149149

150150
## Usage
151151

152-
Here are the step for the LLaMA-7B model:
152+
Here are the step for the LLaMA-7B model.
153+
154+
### Get the Code
153155

154156
```bash
155-
# build this repo
156157
git clone https://github.com/ggerganov/llama.cpp
157158
cd llama.cpp
158-
make
159+
```
160+
161+
### Build
162+
163+
Note: For Windows, CMake or Zig can be used.
164+
165+
1. Use `make`
166+
167+
```bash
168+
make
169+
```
159170

160-
#For Windows and CMake, use the following command instead:
161-
cd <path_to_llama_folder>
162-
mkdir build
163-
cd build
164-
cmake ..
165-
cmake --build . --config Release
171+
1. Use CMake
166172

173+
```bash
174+
mkdir build
175+
cd build
176+
cmake ..
177+
cmake --build . --config Release
178+
```
179+
180+
1. Use Zig
181+
182+
```bash
183+
zig build -Drelease-fast
184+
```
185+
186+
### Prepare Data & Run
187+
188+
```bash
167189
# obtain the original LLaMA model weights and place them in ./models
168190
ls ./models
169191
65B 30B 13B 7B tokenizer_checklist.chk tokenizer.model

build.zig

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
const std = @import("std");
22

3-
pub fn build(b: *std.Build) void {
3+
pub fn build(b: *std.build.Builder) void {
44
const target = b.standardTargetOptions(.{});
5-
const optimize = b.standardOptimizeOption(.{});
5+
const optimize = b.standardReleaseOptions();
66
const want_lto = b.option(bool, "lto", "Want -fLTO");
77

8-
const lib = b.addStaticLibrary(.{
9-
.name = "llama",
10-
.target = target,
11-
.optimize = optimize,
12-
});
8+
const lib = b.addStaticLibrary("llama", null);
139
lib.want_lto = want_lto;
10+
lib.setTarget(target);
11+
lib.setBuildMode(optimize);
1412
lib.linkLibCpp();
1513
lib.addIncludePath(".");
1614
lib.addIncludePath("examples");
@@ -44,16 +42,12 @@ pub fn build(b: *std.Build) void {
4442
fn build_example(comptime name: []const u8, args: anytype) *std.build.LibExeObjStep {
4543
const b = args.b;
4644
const lib = args.lib;
47-
const target = args.target;
48-
const optimize = args.optimize;
4945
const want_lto = args.want_lto;
5046

51-
const exe = b.addExecutable(.{
52-
.name = name,
53-
.target = target,
54-
.optimize = optimize,
55-
});
47+
const exe = b.addExecutable(name, null);
5648
exe.want_lto = want_lto;
49+
lib.setTarget(args.target);
50+
lib.setBuildMode(args.optimize);
5751
exe.addIncludePath(".");
5852
exe.addIncludePath("examples");
5953
exe.addCSourceFiles(&.{

0 commit comments

Comments
 (0)