Skip to content

Commit

Permalink
migrate bigdl-llm to ipex-llm
Browse files Browse the repository at this point in the history
  • Loading branch information
shane-huang committed Mar 25, 2024
1 parent 3d3b46a commit 8e22f08
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# BigDL-LLM\n",
"# IPEX-LLM\n",
"\n",
"> [BigDL-LLM](https://github.com/intel-analytics/BigDL/) is a low-bit LLM optimization library on Intel XPU (Xeon/Core/Flex/Arc/Max). It can make LLMs run extremely fast and consume much less memory on Intel platforms. It is open sourced under Apache 2.0 License.\n",
"> [IPEX-LLM](https://github.com/intel-analytics/ipex-llm/) is a low-bit LLM optimization library on Intel XPU (Xeon/Core/Flex/Arc/Max). It can make LLMs run extremely fast and consume much less memory on Intel platforms. It is open sourced under Apache 2.0 License.\n",
"\n",
"This example goes over how to use LangChain to interact with BigDL-LLM for text generation. \n"
"This example goes over how to use LangChain to interact with IPEX-LLM for text generation. \n"
]
},
{
Expand All @@ -33,7 +33,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Install BigDL-LLM for running LLMs locally on Intel CPU."
"Install IEPX-LLM for running LLMs locally on Intel CPU."
]
},
{
Expand All @@ -42,8 +42,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Install BigDL\n",
"%pip install --pre --upgrade bigdl-llm[all]"
"%pip install --pre --upgrade ipex-llm[all]"
]
},
{
Expand All @@ -60,7 +59,7 @@
"outputs": [],
"source": [
"from langchain.chains import LLMChain\n",
"from langchain_community.llms.bigdl import BigdlLLM\n",
"from langchain_community.llms.ipex_llm import IPEXLLM\n",
"from langchain_core.prompts import PromptTemplate"
]
},
Expand Down Expand Up @@ -110,7 +109,7 @@
}
],
"source": [
"llm = BigdlLLM.from_model_id(\n",
"llm = IPEXLLM.from_model_id(\n",
" model_id=\"lmsys/vicuna-7b-v1.5\",\n",
" model_kwargs={\"temperature\": 0, \"max_length\": 64, \"trust_remote_code\": True},\n",
")"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
logger = logging.getLogger(__name__)


class BigdlLLM(LLM):
"""Wrapper around the BigDL-LLM Transformer-INT4 model
class IPEXLLM(LLM):
"""Wrapper around the IPEX-LLM model
Example:
.. code-block:: python
from langchain.llms import TransformersLLM
llm = TransformersLLM.from_model_id(model_id="THUDM/chatglm-6b")
from langchain.llms import IPEXLLM
llm = IPEXLLM.from_model_id(model_id="THUDM/chatglm-6b")
"""

model_id: str = DEFAULT_MODEL_ID
"""Model name or model path to use."""
model_kwargs: Optional[dict] = None
"""Keyword arguments passed to the model."""
model: Any #: :meta private:
"""BigDL-LLM Transformers-INT4 model."""
"""IPEXLLM model."""
tokenizer: Any #: :meta private:
"""Huggingface tokenizer model."""
streaming: bool = True
Expand Down Expand Up @@ -56,16 +56,16 @@ def from_model_id(
An object of TransformersLLM.
"""
try:
from bigdl.llm.transformers import (
from ipex_llm.transformers import (
AutoModel,
AutoModelForCausalLM,
)
from transformers import AutoTokenizer, LlamaTokenizer

except ImportError:
raise ValueError(
"Could not import bigdl-llm or transformers. "
"Please install it with `pip install --pre --upgrade bigdl-llm[all]`."
"Could not import ipex_llm or transformers. "
"Please install it with `pip install --pre --upgrade ipex_llm[all]`."
)

_model_kwargs = model_kwargs or {}
Expand Down Expand Up @@ -109,24 +109,24 @@ def from_model_id_low_bit(
Args:
model_id: Path for the bigdl transformers low-bit model checkpoint folder.
model_id: Path for the ipex-llm transformers low-bit model checkpoint folder.

Check failure on line 112 in libs/community/langchain_community/llms/ipex_llm.py

View workflow job for this annotation

GitHub Actions / cd libs/community / make lint #3.8

Ruff (E501)

langchain_community/llms/ipex_llm.py:112:89: E501 Line too long (89 > 88)

Check failure on line 112 in libs/community/langchain_community/llms/ipex_llm.py

View workflow job for this annotation

GitHub Actions / cd libs/community / make lint #3.11

Ruff (E501)

langchain_community/llms/ipex_llm.py:112:89: E501 Line too long (89 > 88)
model_kwargs: Keyword arguments to pass to the model and tokenizer.
kwargs: Extra arguments to pass to the model and tokenizer.
Returns:
An object of TransformersLLM.
"""
try:
from bigdl.llm.transformers import (
from ipex_llm.transformers import (
AutoModel,
AutoModelForCausalLM,
)
from transformers import AutoTokenizer, LlamaTokenizer

except ImportError:
raise ValueError(
"Could not import bigdl-llm or transformers. "
"Please install it with `pip install --pre --upgrade bigdl-llm[all]`"
"Could not import ipex_llm or transformers. "
"Please install it with `pip install --pre --upgrade ipex_llm[all]`"
)

_model_kwargs = model_kwargs or {}
Expand Down Expand Up @@ -163,7 +163,7 @@ def _identifying_params(self) -> Mapping[str, Any]:

@property
def _llm_type(self) -> str:
return "BigDL-llm"
return "ipex-llm"

def _call(
self,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Test BigDL LLM"""
"""Test IPEX LLM"""
from langchain_core.outputs import LLMResult

from langchain_community.llms.bigdl import BigdlLLM
from langchain_community.llms.ipex_llm import IPEXLLM


def test_call() -> None:
"""Test valid call to baichuan."""
llm = BigdlLLM.from_model_id(
"""Test valid call to ipex-llm."""
llm = IPEXLLM.from_model_id(
model_id="lmsys/vicuna-7b-v1.5",
model_kwargs={"temperature": 0, "max_length": 16, "trust_remote_code": True},
)
Expand All @@ -15,8 +15,8 @@ def test_call() -> None:


def test_generate() -> None:
"""Test valid call to baichuan."""
llm = BigdlLLM.from_model_id(
"""Test valid call to ipex-llm."""
llm = IPEXLLM.from_model_id(
model_id="lmsys/vicuna-7b-v1.5",
model_kwargs={"temperature": 0, "max_length": 16, "trust_remote_code": True},
)
Expand Down

0 comments on commit 8e22f08

Please sign in to comment.