Skip to content

Commit

Permalink
return last tokenizer if many
Browse files Browse the repository at this point in the history
  • Loading branch information
mitya52 committed Jun 19, 2024
1 parent 4048d55 commit e693243
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions refact_webgui/webgui/selfhost_fastapi_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,12 @@ def _select_default_lora_if_exists(model_name: str, running_models: List[str]):

async def _local_tokenizer(self, model_path: str) -> str:
model_dir = Path(env.DIR_WEIGHTS) / f"models--{model_path.replace('/', '--')}"
tokenizer_paths = list(model_dir.rglob("tokenizer.json"))
tokenizer_paths = list(sorted(model_dir.rglob("tokenizer.json"), key=lambda p: p.stat().st_ctime))
if not tokenizer_paths:
raise HTTPException(404, detail=f"tokenizer.json for {model_path} does not exist")
if len(tokenizer_paths) > 1:
raise HTTPException(404, detail=f"multiple tokenizer.json for {model_path}")

data = ""
async with aiofiles.open(tokenizer_paths[0], mode='r') as f:
async with aiofiles.open(tokenizer_paths[-1], mode='r') as f:
while True:
if not (chunk := await f.read(1024 * 1024)):
break
Expand Down

0 comments on commit e693243

Please sign in to comment.