Skip to content

Commit

Permalink
optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjoyo committed Apr 25, 2024
1 parent 9cc5f06 commit 7396795
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 119 deletions.
8 changes: 5 additions & 3 deletions bpm_ai_inference/llm/llama_cpp/llama_chat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import os
import re
from typing import Dict, Any, Optional, List

Expand All @@ -13,6 +14,7 @@
from bpm_ai_inference.llm.llama_cpp._constants import DEFAULT_MODEL, DEFAULT_TEMPERATURE, DEFAULT_MAX_RETRIES, \
DEFAULT_QUANT_BALANCED
from bpm_ai_inference.llm.llama_cpp.util import messages_to_llama_dicts
from bpm_ai_inference.util import FORCE_OFFLINE_FLAG
from bpm_ai_inference.util.files import find_file
from bpm_ai_inference.util.hf import hf_home

Expand Down Expand Up @@ -40,7 +42,7 @@ def __init__(
filename: str = DEFAULT_QUANT_BALANCED,
temperature: float = DEFAULT_TEMPERATURE,
max_retries: int = DEFAULT_MAX_RETRIES,
force_offline: bool = False
force_offline: bool = os.getenv(FORCE_OFFLINE_FLAG, False)
):
if not has_llama_cpp_python:
raise ImportError('llama-cpp-python is not installed')
Expand All @@ -52,8 +54,9 @@ def __init__(
)
n_ctx = 4096
if force_offline:
model_file = find_file(hf_home() + "hub/models--" + model.replace("/", "--"), filename)
self.llm = Llama(
model_path=find_file(hf_home() + "hub/models--" + model.replace("/", "--"), filename),
model_path=model_file,
n_ctx=n_ctx,
verbose=False
)
Expand All @@ -65,7 +68,6 @@ def __init__(
verbose=False
)


async def _generate_message(
self,
messages: List[ChatMessage],
Expand Down
1 change: 0 additions & 1 deletion bpm_ai_inference/ocr/tesseract.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import logging
import os
import urllib
Expand Down
1 change: 0 additions & 1 deletion bpm_ai_inference/pos/spacy_pos_tagger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import logging

from bpm_ai_core.pos.pos_tagger import POSTagger, POSResult
Expand Down
1 change: 0 additions & 1 deletion bpm_ai_inference/question_answering/pix2struct_vqa.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import logging

from bpm_ai_core.llm.common.blob import Blob
Expand Down
1 change: 0 additions & 1 deletion bpm_ai_inference/question_answering/transformers_docvqa.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import logging

from bpm_ai_core.llm.common.blob import Blob
Expand Down
1 change: 0 additions & 1 deletion bpm_ai_inference/speech_recognition/faster_whisper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import io

from bpm_ai_core.speech_recognition.asr import ASRModel, ASRResult
Expand Down
1 change: 0 additions & 1 deletion bpm_ai_inference/translation/easy_nmt/easy_nmt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import json
import logging
import math
Expand Down
1 change: 1 addition & 0 deletions bpm_ai_inference/util/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FORCE_OFFLINE_FLAG = "FORCE_OFFLINE"
2 changes: 1 addition & 1 deletion bpm_ai_inference/util/optimum.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from huggingface_hub import HfFileSystem
from optimum.onnxruntime import ORTModelForSequenceClassification, ORTOptimizer, ORTQuantizer, \
ORTModelForQuestionAnswering, ORTModel
from optimum.onnxruntime.configuration import OptimizationConfig, AutoQuantizationConfig, AutoOptimizationConfig
from optimum.onnxruntime.configuration import AutoQuantizationConfig, AutoOptimizationConfig
from transformers import AutoTokenizer

from bpm_ai_inference.util.hf import hf_home
Expand Down
216 changes: 109 additions & 107 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.11,<3.12"
bpm-ai-core = "^2.4.2"
bpm-ai-core = "^2.5.0"
langfuse = "^2.7.6"
faster-whisper = "^0.10.0"
lingua-language-detector = "^2.0.2"
pytesseract = "^0.3.10"
transformers = "^4.37.2"
transformers = "^4.39.3"
sacremoses = "^0.1.1"
sentencepiece = "^0.2.0"
nltk = "^3.8.0"
Expand Down

0 comments on commit 7396795

Please sign in to comment.