Skip to content

Add quantize script for batch quantization#92

Merged
ggerganov merged 5 commits intomasterfrom
quantize-sh
Mar 13, 2023
Merged

Add quantize script for batch quantization#92
ggerganov merged 5 commits intomasterfrom
quantize-sh

Conversation

@prusnak
Copy link
Copy Markdown
Contributor

@prusnak prusnak commented Mar 13, 2023

Alternative to #17 suggested in #17 (comment)

@ggerganov ggerganov merged commit d1f2247 into master Mar 13, 2023
@ggerganov ggerganov deleted the quantize-sh branch March 13, 2023 16:15
@Jettford
Copy link
Copy Markdown

I wrote up a basic python implementation of the same script for Windows users, would it be worth making a pull request to replace the batch script?

import os
import re
import sys

def print_usage():
    print("Usage: llama-quantize.py 7B|13B|30B|65B [--remove-f16]")
    exit(0)

if not len(sys.argv) > 1:
    print_usage()
    
regex_test = re.compile("^[0-9]{1,2}B$")

if not regex_test.match(sys.argv[1]):
    print_usage()
    
model_directory = f"./models/{sys.argv[1]}/"

if not os.path.exists(model_directory):
    print("Failed to find model directory")
    
    print_usage()
    
for file in os.listdir(model_directory):
    if not "ggml-model-f16.bin" in file:
        continue
        
    file = os.path.join(model_directory, file)
    
    new_name = file.replace("f16", "q4_0")
    
    binary_name = "./quantize"
    
    if sys.platform == "win32":
        binary_name += ".exe"
        
        binary_name = binary_name[2:]
        
    os.system(f"{binary_name} {file} {new_name} 2")
    
    if len(sys.argv) > 2:
        if sys.argv[2] == "--remove-f16":
            os.remove(file)

@ghost

This comment was marked as outdated.

@tmzncty
Copy link
Copy Markdown

tmzncty commented Mar 16, 2023

我觉得,直接编译出quantize.exe,然后在CMD中运行就好了。
‘‘‘quantize.exe ggml-model-f16.bin ggml-model-q4.bin 2’’’
image
image
image
image

dmahurin pushed a commit to dmahurin/llama.cpp that referenced this pull request May 31, 2023
dmahurin pushed a commit to dmahurin/llama.cpp that referenced this pull request Jun 1, 2023
Deadsg pushed a commit to Deadsg/llama.cpp that referenced this pull request Dec 19, 2023
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
* Add quantize script for batch quantization

* Indentation

* README for new quantize.sh

* Fix script name

* Fix file list on Mac OS

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants