Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Community] Update optimization logic regarding device for llama-index-embeddings-ipex-llm #25

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
from llama_index.core.bridge.pydantic import Field, PrivateAttr
from llama_index.core.callbacks import CallbackManager
from llama_index.core.utils import get_cache_dir, infer_torch_device
from llama_index.core.utils import get_cache_dir
from llama_index.embeddings.ipex_llm.utils import (
DEFAULT_HUGGINGFACE_EMBEDDING_MODEL,
BGE_MODELS,
Expand Down Expand Up @@ -57,7 +57,15 @@ def __init__(
callback_manager: Optional[CallbackManager] = None,
**model_kwargs,
):
self._device = device or infer_torch_device()
# Set "cpu" as default device
self._device = device or "cpu"

if self._device not in ["cpu", "xpu"]:
logger.warning(
"IpexLLMEmbedding currently only supports device to be 'cpu' or 'xpu', "
f"but you have: {self._device}; Use 'cpu' instead."
)
self._device = "cpu"

cache_folder = cache_folder or get_cache_dir()

Expand All @@ -84,13 +92,11 @@ def __init__(
**model_kwargs,
)

if self._device == "cpu":
self._model = _optimize_pre(self._model)
self._model = _optimize_post(self._model)
# TODO: optimize using ipex-llm optimize_model
elif self._device == "xpu":
self._model = _optimize_pre(self._model)
self._model = _optimize_post(self._model)
# Apply ipex-llm optimizations
self._model = _optimize_pre(self._model)
self._model = _optimize_post(self._model)
if self._device == "xpu":
# TODO: apply `ipex_llm.optimize_model`
self._model = self._model.half().to(self._device)

if max_length:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ license = "MIT"
name = "llama-index-embeddings-ipex-llm"
packages = [{include = "llama_index/"}]
readme = "README.md"
version = "0.1.1"
version = "0.1.2"

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
Expand Down
Loading