Skip to content

Commit

Permalink
update llama convert and migrate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
1b5d committed Apr 13, 2023
1 parent 532e01b commit 818b96c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions app/llms/llama/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@ class LlamaLLM(BaseLLM):
Llama LLM implementation
"""

def _setup(self):
model_path = os.path.join(
settings.models_dir,
f"ggml-{settings.model_family}-{settings.model_name}-q4.bin",
)

def _download(self, model_path):
if os.path.exists(model_path):
logger.info("found an existing model %s", model_path)
return model_path
return

logger.info("downloading model to %s", model_path)

Expand All @@ -49,6 +44,14 @@ def _setup(self):
model_path,
)

def _setup(self):
model_path = os.path.join(
settings.models_dir,
f"ggml-{settings.model_family}-{settings.model_name}-q4.bin",
)

self._download(model_path=model_path)

if settings.setup_params["convert"]:
tokenizer_model_path = os.path.join(settings.models_dir, "tokenizer.model")
logger.info("downloading tokenizer model %s", tokenizer_model_path)
Expand All @@ -67,14 +70,18 @@ def _setup(self):
)
)
logger.info("converting model %s", model_path)
convert_one_file(model_path, tokenizer)
try:
convert_one_file(model_path, tokenizer)
except Exception as exp: # pylint: disable=broad-exception-caught
logger.warning("Could not convert the model %s", str(exp))

if settings.setup_params["migrate"]:
logger.info("migrating model %s", model_path)
migrate(model_path)
# clean up backed model since we won't need it
logger.info("cleaning up ..")
os.remove(model_path + ".orig")
if os.path.exists(model_path + ".orig"):
os.remove(model_path + ".orig")

logger.info("setup done successfully for %s", model_path)
return model_path
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ filelock==3.10.7
h11==0.14.0
huggingface-hub==0.13.3
idna==3.4
llama-cpp-python==0.1.26
llama-cpp-python==0.1.33
numpy==1.24.2
packaging==23.0
pydantic==1.10.7
Expand Down

0 comments on commit 818b96c

Please sign in to comment.