Skip to content

Commit

Permalink
Error handling output_dir in quantize_model
Browse files Browse the repository at this point in the history
  • Loading branch information
arjbingly committed May 2, 2024
1 parent bc9a48d commit 26037b8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/grag/quantize/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ def fetch_model_repo(repo_id: str, model_path: Union[str, Path] = './grag-quanti


def quantize_model(
model_dir_path: Union[str, Path],
quantization: str,
root_quantize: Union[str, Path] = './grag-quantize', # path with both build and llamacpp
output_dir: Optional[Path] = None,
model_dir_path: Union[str, Path],
quantization: str,
root_quantize: Union[str, Path] = './grag-quantize', # path with both build and llamacpp
output_dir: Optional[Union[Path, str]] = None,
) -> Tuple[Path, Path]:
"""Quantizes a specified model using a given quantization level and saves it to an optional directory. If the output directory is not specified, it defaults to a subdirectory under the provided model directory. The function also handles specific exceptions during the conversion process and ensures the creation of the necessary directories.
Expand All @@ -160,10 +160,11 @@ def quantize_model(
if output_dir is None:
try:
output_dir = Path(config["llm"]["base_dir"])
except KeyError:
except (KeyError, TypeError):
output_dir = Path('.')

output_dir = Path(output_dir) / model_dir_path.name if output_dir.stem != model_dir_path.name else output_dir
else:
output_dir = Path(output_dir)
output_dir = output_dir / model_dir_path.name if output_dir.stem != model_dir_path.name else output_dir
output_dir.mkdir(parents=True, exist_ok=True)
output_dir = output_dir.resolve()

Expand Down

0 comments on commit 26037b8

Please sign in to comment.