Skip to content

Commit

Permalink
handle site packages better
Browse files Browse the repository at this point in the history
  • Loading branch information
xhedit authored Mar 20, 2024
1 parent a3928d5 commit 8ac705b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion quantkit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def safetensor(model, delete_original):
@click.option('--output', '-out', help='output name')
@click.option('--keep/--delete', help='keep intermediate conversion GGUF')
@click.option('--f32/--f16', default=False, help='intermediate conversion step uses f32 (requires much more disk space)')
@click.option('--built-in-imatrix/--disable-built-in-imatrix', default=True, help='use built in imatrix')
@click.option('--built-in-imatrix/--disable-built-in-imatrix', default=False, help='use built in imatrix')
@click.option('--imatrix', help='Specify pre-generated imatrix')
@click.option('--cal-file', help='Specify calibration dataset')
@click.option('--n-gpu-layers', "-ngl", default=0, help='how many layers to offload to GPU for imatrix')
Expand Down
21 changes: 18 additions & 3 deletions quantkit/quantkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ def run_safetensor(model, delete_original):
convert_multi(model_dir, del_pytorch_model=delete_original)

def run_gguf(model, quant_type, output, keep, f32, built_in_imatrix, imatrix, cal_file, n_gpu_layers):
if not Path(cal_file).is_file():
print(f"quantkit: could not load {cal_file}")
return
if cal_file is not None:
if not Path(cal_file).is_file():
print(f"quantkit: could not load {cal_file}")
return

path = Path(model)
if path.is_dir():
Expand Down Expand Up @@ -98,6 +99,13 @@ def run_imatrix(cal_file, n_gpu_layers):

site_dir = site.getusersitepackages()
imatrix = Path(site_dir) / "bin" / "imatrix"

if not imatrix.is_file():
for d in site.getsitepackages():
if(Path(d) / "bin" / "imatrix").is_file():
site_dir = d
imatrix = d / "bin" / "imatrix"

print(f"Attempting to execute {imatrix}")

if cal_file is None:
Expand Down Expand Up @@ -125,6 +133,13 @@ def quantize(gguf_file, output, quant_type, imatrix):

site_dir = site.getusersitepackages()
quantize = Path(site_dir) / "bin" / "quantize"

if not quantize.is_file():
for d in site.getsitepackages():
if(Path(d) / "bin" / "quantize").is_file():
site_dir = d
quantize = d / "bin" / "quantize"

print(f"Attempting to execute {quantize}")

if imatrix is None:
Expand Down

0 comments on commit 8ac705b

Please sign in to comment.