Skip to content
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

Add integration with gemlite weight only quant #2528

Merged
merged 7 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions python/sglang/bench_offline_throughput.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ def throughput_test(
dataset_path=bench_args.dataset_path,
)

import os, pwd
print(f"/tmp/{pwd.getpwuid(os.getuid()).pw_gecos}_gemlite.json")

# Warm up
if not bench_args.skip_warmup:
logging.info("\nWarmup...")
Expand All @@ -322,6 +325,13 @@ def throughput_test(
)
time.sleep(0.5)

try:
from gemlite.core import GemLiteLinearTriton
import os, pwd
GemLiteLinearTriton.cache_config(f"/tmp/{pwd.getpwuid(os.getuid()).pw_gecos}_gemlite.json")
except ImportError:
pass

logging.info("\nBenchmark...")
result = throughput_test_once(
backend_name=bench_args.backend,
Expand Down
8 changes: 8 additions & 0 deletions python/sglang/bench_one_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ def latency_test(
8, # shorter decoding to speed up the warmup
server_args.device,
)

try:
from gemlite.core import GemLiteLinearTriton
import os, pwd
GemLiteLinearTriton.cache_config(f"/tmp/{pwd.getpwuid(os.getuid()).pw_gecos}_gemlite.json")
except ImportError:
pass

rank_print("Benchmark ...")

# Run the sweep
Expand Down
26 changes: 26 additions & 0 deletions python/sglang/srt/layers/torchao_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ def filter_fn(module, fqn):
256,
], f"int4wo groupsize needs to be one of [32, 64, 128, 256] but got {group_size}"
quantize_(model, int4_weight_only(group_size=group_size), filter_fn=filter_fn)
elif "gemlite" in torchao_config:
# gemlite-<packing_bitwidth>-<bit_width>-<group_size> or
# gemlite-<bit_width>-<group_size> (packing_bitwidth defaults to 32)
import os, pwd
import gemlite
from gemlite.core import GemLiteLinearTriton, set_autotune
from torchao.quantization import gemlite_uintx_weight_only

_quant_args = torchao_config.split("-")
bit_width = int(_quant_args[-2])
group_size = None if _quant_args[-1] == 'None' else int(_quant_args[-1])
try:
packing_bitwidth = int(_quant_args[-3])
except:
# if only 2 inputs found, use default value
packing_bitwidth = 32

quantize_(model, gemlite_uintx_weight_only(group_size, bit_width, packing_bitwidth))

# try to load gemlite kernel config
try:
GemLiteLinearTriton.load_config(f"/tmp/{pwd.getpwuid(os.getuid()).pw_gecos}_gemlite.json")
print(f"loaded gemlite kernel cache /tmp/{pwd.getpwuid(os.getuid()).pw_gecos}_gemlite.json")
except:
merrymercy marked this conversation as resolved.
Show resolved Hide resolved
print(f"unable to load gemlite kernel cache /tmp/{pwd.getpwuid(os.getuid()).pw_gecos}_gemlite.json")

elif "fp8wo" in torchao_config:
# this requires newer hardware
# [rank0]: AssertionError: fp8e4nv data type is not supported on CUDA arch < 89
Expand Down
Loading