Skip to content

Creating an initial Quantization Directory #863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ jobs:
run: |
mkdir gguf_files
wget -O gguf_files/llama-2-7b.Q4_0.gguf "https://huggingface.co/TheBloke/Llama-2-7B-GGUF/resolve/main/llama-2-7b.Q4_0.gguf?download=true"
./llama.cpp/quantize --allow-requantize gguf_files/llama-2-7b.Q4_0.gguf gguf_files/llama-2-7b.Q4_0.requant_F32.gguf F32
./llama.cpp/llama-quantize --allow-requantize gguf_files/llama-2-7b.Q4_0.gguf gguf_files/llama-2-7b.Q4_0.requant_F32.gguf F32
- name: Load files
run: |
Expand Down
2 changes: 1 addition & 1 deletion build/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import torch._inductor.config

from config.model_config import resolve_model_config
from quantize import quantize_model
from quantization.quantize import quantize_model

from build.model import Transformer
from build.utils import device_sync, is_cpu_device, is_cuda_or_cpu_device, name_to_dtype
Expand Down
2 changes: 1 addition & 1 deletion build/gguf_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import torch

from gguf import GGUFValueType
from quantize import pack_scales_and_zeros, WeightOnlyInt4Linear
from quantization.quantize import pack_scales_and_zeros, WeightOnlyInt4Linear

from build.gguf_util import Q4_0, to_float
from build.model import ModelArgs, Transformer
Expand Down
2 changes: 1 addition & 1 deletion build/gguf_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import gguf
import torch
from quantize import group_dequantize_tensor_from_qparams
from quantization.quantize import group_dequantize_tensor_from_qparams


def to_float(t: gguf.gguf_reader.ReaderTensor):
Expand Down
2 changes: 1 addition & 1 deletion docs/quantization.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ for valid `bitwidth` and `groupsize` values.
| linear with HQQ (asymmetric) |`'{"linear:hqq" : {"groupsize" : <groupsize>}}'`|
| embedding | `'{"embedding": {"bitwidth": <bitwidth>, "groupsize":<groupsize>}}'` |

See the available quantization schemes [here](https://github.com/pytorch/torchchat/blob/main/quantize.py#L1260-L1266).
See the available quantization schemes [here](https://github.com/pytorch/torchchat/blob/main/quantization/quantize.py#L1260-L1266).

## Examples
We can mix and match weight quantization with embedding quantization.
Expand Down
4 changes: 2 additions & 2 deletions install_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $PIP_EXECUTABLE install -r requirements.txt --extra-index-url https://download.p
# NOTE: If a newly-fetched version of the executorch repo changes the value of
# NIGHTLY_VERSION, you should re-run this script to install the necessary
# package versions.
NIGHTLY_VERSION=dev20240604
NIGHTLY_VERSION=dev20240613

# Uninstall triton, as nightly will depend on pytorch-triton, which is one and the same
$PIP_EXECUTABLE uninstall -y triton
Expand All @@ -63,7 +63,7 @@ fi

# pip packages needed by exir.
REQUIREMENTS_TO_INSTALL=(
torch=="2.4.0.${NIGHTLY_VERSION}"
torch=="2.5.0.${NIGHTLY_VERSION}"
)

# Install the requirements. `--extra-index-url` tells pip to look for package
Expand Down
2 changes: 1 addition & 1 deletion qops.py → quantization/qops.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def _check_k(cls, *, k, groupsize=1, inner_k_tiles=1):
def _prepare_weight_and_scales_and_zeros(
cls, weight_bf16, groupsize, inner_k_tiles
):
from quantize import group_quantize_tensor
from quantization.quantize import group_quantize_tensor

weight_int32, scales_and_zeros = group_quantize_tensor(
weight_bf16, n_bit=4, groupsize=groupsize
Expand Down
2 changes: 1 addition & 1 deletion quantize.py → quantization/quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
state_dict_device,
)

from qops import (
from quantization.qops import (
LinearAct8Int4DQ,
LinearInt4 as WeightOnlyInt4Linear,
LinearInt8 as WeightOnlyInt8Linear,
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ tiktoken
# Miscellaneous
snakeviz
sentencepiece
numpy
numpy < 2.0
gguf
lm-eval==0.4
lm-eval==0.4.2
blobfile

# Build tools
Expand Down
Loading