Skip to content

Commit ef51e9e

Browse files
authored
Merge branch 'ggerganov:master' into hipblas
2 parents d571d16 + 4afcc37 commit ef51e9e

11 files changed

+330
-160
lines changed

SHA256SUMS

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
700df0d3013b703a806d2ae7f1bfb8e59814e3d06ae78be0c66368a50059f33d models/7B/consolidated.00.pth
22
666a4bb533b303bdaf89e1b6a3b6f93535d868de31d903afdc20983dc526c847 models/7B/ggml-model-f16.bin
3-
fcb7664c2e69776920b526362a243e912f73c36b1ec892eb354bab940f5edb5a models/7B/ggml-model-q4_0.bin
3+
99aeb35f26b577fa2732716cca4d8b5ada39a78ea9b2dca2651fc632b5d101b6 models/7B/ggml-model-q4_0.bin
44
cc061458339a3eb8bcecbf0a825e9924fb7d1a8150f63cd5d091caa99215aafe models/7B/ggml-model-q4_1.bin
5-
1bc7484c24a87612726d756f1761890e7acf5f412e23378577ce50fbe789b5b8 models/7B/ggml-model-q4_2.bin
5+
25b050337a87344da687a7f2adddc03bd99b7f6c140450e836649f3585fb6496 models/7B/ggml-model-q4_2.bin
66
3429bf198ec771886cf81a574df45245f3ebf04f0ce0956b73ef5d0ab01ff48b models/7B/ggml-model-q4_3.bin
77
7e89e242ddc0dd6f060b43ca219ce8b3e8f08959a72cb3c0855df8bb04d46265 models/7B/params.json
88
745bf4e29a4dd6f411e72976d92b452da1b49168a4f41c951cfcc8051823cf08 models/13B/consolidated.00.pth
99
d5ccbcc465c71c0de439a5aeffebe8344c68a519bce70bc7f9f92654ee567085 models/13B/consolidated.01.pth
1010
2b206e9b21fb1076f11cafc624e2af97c9e48ea09312a0962153acc20d45f808 models/13B/ggml-model-f16.bin
11-
4b69e4d6b6e3275230955997b90407fceca7e5ab3daf2e63a2c9e7270a8e1e3e models/13B/ggml-model-q4_0.bin
11+
eecb575d325d935157761172e2bf05984dad216eb2b06777b73463cf9b818bab models/13B/ggml-model-q4_0.bin
1212
d9581b5b88e5622532fe897c9f9b0e67a317d22dd27a6f90fa4ab8c6d23ccdbb models/13B/ggml-model-q4_1.bin
13-
8d55a2077317ec9a928c7851d6a43e08e51f7e9e08360f2a7a7e1deefea3134f models/13B/ggml-model-q4_2.bin
13+
75a218a47df03f5f96354656329864613abcb67779412b9bc2282b28c1c3cbaa models/13B/ggml-model-q4_2.bin
1414
4208cdec9788ffa48dc1a17af2c36a0299f5bf3eb0e2b87889dda7fad591fca3 models/13B/ggml-model-q4_3.bin
1515
4ab77bec4d4405ccb66a97b282574c89a94417e3c32e5f68f37e2876fc21322f models/13B/params.json
1616
e23294a58552d8cdec5b7e8abb87993b97ea6eced4178ff2697c02472539d067 models/30B/consolidated.00.pth
1717
4e077b7136c7ae2302e954860cf64930458d3076fcde9443f4d0e939e95903ff models/30B/consolidated.01.pth
1818
24a87f01028cbd3a12de551dcedb712346c0b5cbdeff1454e0ddf2df9b675378 models/30B/consolidated.02.pth
1919
1adfcef71420886119544949767f6a56cb6339b4d5fcde755d80fe68b49de93b models/30B/consolidated.03.pth
2020
7e1b524061a9f4b27c22a12d6d2a5bf13b8ebbea73e99f218809351ed9cf7d37 models/30B/ggml-model-f16.bin
21-
7a679908ce31c9d6ae2e38d6059bcd4d0ad3a870cd58cc1c8f7b36f2b2f51c73 models/30B/ggml-model-q4_0.bin
21+
517b9e525742c42b5478a6280a4b41ec66f46298c57aba7f0453d491682fe42d models/30B/ggml-model-q4_0.bin
2222
7b75ac615fa369ee593493a7e6ef87542bf0350255db928b22c5a24f6d598bcd models/30B/ggml-model-q4_1.bin
23-
2c82b4954a94a6a284f452f6011c1e4f0d20362c194a0b1eb5737f5fd8a20fb3 models/30B/ggml-model-q4_2.bin
23+
aadbc9cf806313a55be570f62884eed289d30c313fac3b7838717e01bd553204 models/30B/ggml-model-q4_2.bin
2424
a6188660199dbcb8d5658abe7d89169869e50423494385830d9e6b330ea7fc33 models/30B/ggml-model-q4_3.bin
2525
2c07118ea98d69dbe7810d88520e30288fa994751b337f8fca02b171955f44cb models/30B/params.json
2626
135c563f6b3938114458183afb01adc9a63bef3d8ff7cccc3977e5d3664ecafe models/65B/consolidated.00.pth
@@ -32,9 +32,9 @@ a287c0dfe49081626567c7fe87f74cce5831f58e459b427b5e05567641f47b78 models/65B/con
3232
72b4eba67a1a3b18cb67a85b70f8f1640caae9b40033ea943fb166bd80a7b36b models/65B/consolidated.06.pth
3333
d27f5b0677d7ff129ceacd73fd461c4d06910ad7787cf217b249948c3f3bc638 models/65B/consolidated.07.pth
3434
60758f2384d74e423dffddfd020ffed9d3bb186ebc54506f9c4a787d0f5367b0 models/65B/ggml-model-f16.bin
35-
c671fe1bce71499ac732ec999770ebe53ac486623a7891e42c9dfdb6962d2c64 models/65B/ggml-model-q4_0.bin
35+
01672072136f8be6ca9d7cebe5f86ed316e8b85851b9fe3de951809233cea4f2 models/65B/ggml-model-q4_0.bin
3636
4743a28aac3e5f32a6e838a815f51d3779de44fbbe251d745251e66c23c5950f models/65B/ggml-model-q4_1.bin
37-
4a145a210c56982389b1ed34387e0590c3e0d7325fa9be4f2284fe4d244a3633 models/65B/ggml-model-q4_2.bin
37+
1b6f6588d0e2ecfe6c4d849088e48e5e3083466b962daa32e3261363e21fc5e9 models/65B/ggml-model-q4_2.bin
3838
305e91a4608b4f627b9b8ad5b4af75187d2684254bfd76dcb9db571618ef293c models/65B/ggml-model-q4_3.bin
3939
999ed1659b469ccc2a941714c0a9656fa571d17c9f7c8c7589817ca90edef51b models/65B/params.json
4040
9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347 models/tokenizer.model

convert-lora-to-ggml.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ def translate_tensor_name(t: str) -> str:
4949
def write_file_header(fout: TextIO, params: Dict[str, Any]) -> None:
5050
fout.write(b"ggla"[::-1]) # magic (ggml lora)
5151
fout.write(struct.pack("i", 1)) # file version
52-
fout.write(struct.pack("ii", params["r"], params["lora_alpha"]))
52+
fout.write(struct.pack("i", params["r"]))
53+
# https://opendelta.readthedocs.io/en/latest/modules/deltas.html says that `lora_alpha` is an int
54+
# but some models ship a float value instead
55+
# let's convert to int, but fail if lossless conversion is not possible
56+
assert int(params["lora_alpha"]) == params["lora_alpha"], "cannot convert float to int losslessly"
57+
fout.write(struct.pack("i", int(params["lora_alpha"])))
5358

5459

5560
def write_tensor_header(
@@ -89,7 +94,7 @@ def write_tensor_header(
8994
print(f"Error: unsupported adapter type {params['peft_type']}, expected LORA")
9095
sys.exit(1)
9196

92-
if params["fan_in_fan_out"] == True:
97+
if params["fan_in_fan_out"] is True:
9398
print("Error: param fan_in_fan_out is not supported")
9499
sys.exit(1)
95100

examples/quantize/quantize.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int main(int argc, char ** argv) {
1616
fprintf(stderr, " type = %d - q4_1\n", LLAMA_FTYPE_MOSTLY_Q4_1);
1717
fprintf(stderr, " type = %d - q4_2\n", LLAMA_FTYPE_MOSTLY_Q4_2);
1818
fprintf(stderr, " type = %d - q4_3\n", LLAMA_FTYPE_MOSTLY_Q4_3);
19+
fprintf(stderr, " type = %d - q8_0\n", LLAMA_FTYPE_MOSTLY_Q8_0);
1920
return 1;
2021
}
2122

flake.nix

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
mv bin/* $out/bin/
3131
mv $out/bin/main $out/bin/llama
3232
33-
echo "#!${llama-python}/bin/python" > $out/bin/convert-pth-to-ggml
34-
cat ${./convert-pth-to-ggml.py} >> $out/bin/convert-pth-to-ggml
35-
chmod +x $out/bin/convert-pth-to-ggml
33+
echo "#!${llama-python}/bin/python" > $out/bin/convert.py
34+
cat ${./convert.py} >> $out/bin/convert.py
35+
chmod +x $out/bin/convert.py
3636
'';
3737
meta.mainProgram = "llama";
3838
};

ggml-cuda.cu

+28
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ typedef struct {
4141
} block_q4_3;
4242
static_assert(sizeof(block_q4_3) == 2 * sizeof(ggml_fp16_t) + QK4_3 / 2, "wrong q4_3 block size/padding");
4343

44+
#define QK8_0 32
45+
typedef struct {
46+
float d; // delta
47+
int8_t qs[QK8_0]; // quants
48+
} block_q8_0;
49+
static_assert(sizeof(block_q8_0) == sizeof(float) + QK8_0, "wrong q8_0 block size/padding");
50+
4451
static __global__ void dequantize_block_q4_0(const void * vx, float * y) {
4552
const block_q4_0 * x = (const block_q4_0 *) vx;
4653

@@ -135,6 +142,22 @@ static __global__ void dequantize_block_q4_3(const void * vx, float * y) {
135142
}
136143
}
137144

145+
static __global__ void dequantize_block_q8_0(const void * vx, float * y) {
146+
const block_q8_0 * x = (const block_q8_0 *) vx;
147+
148+
const int i = blockIdx.x;
149+
150+
const float d = x[i].d;
151+
152+
const int8_t * pp = x[i].qs;
153+
154+
for (int l = 0; l < QK8_0; l++) {
155+
const int8_t vi = pp[l];
156+
157+
y[i*QK8_0 + l] = vi*d;
158+
}
159+
}
160+
138161
void dequantize_row_q4_0_cuda(const void * vx, float * y, int k, cudaStream_t stream) {
139162
const int nb = k / QK4_0;
140163
dequantize_block_q4_0<<<nb, 1, 0, stream>>>(vx, y);
@@ -155,6 +178,11 @@ void dequantize_row_q4_3_cuda(const void * vx, float * y, int k, cudaStream_t st
155178
dequantize_block_q4_3<<<nb, 1, 0, stream>>>(vx, y);
156179
}
157180

181+
void dequantize_row_q8_0_cuda(const void * vx, float * y, int k, cudaStream_t stream) {
182+
const int nb = k / QK8_0;
183+
dequantize_block_q8_0<<<nb, 1, 0, stream>>>(vx, y);
184+
}
185+
158186
// buffer pool for cuda
159187
#define MAX_CUDA_BUFFERS 16
160188

ggml-cuda.h

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ void dequantize_row_q4_0_cuda(const void * vx, float * y, int k, cudaStream_t st
6767
void dequantize_row_q4_1_cuda(const void * vx, float * y, int k, cudaStream_t stream);
6868
void dequantize_row_q4_2_cuda(const void * vx, float * y, int k, cudaStream_t stream);
6969
void dequantize_row_q4_3_cuda(const void * vx, float * y, int k, cudaStream_t stream);
70+
void dequantize_row_q8_0_cuda(const void * vx, float * y, int k, cudaStream_t stream);
7071

7172
#ifdef __cplusplus
7273
}

0 commit comments

Comments
 (0)