-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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: Fuse HuggingFace Endpoint-related classes into one #17254
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
2dcee49
to
5b02bc6
Compare
@andrewrreed @Jofthomas if you want to take a look at the PR! |
edf5b20
to
a55b398
Compare
@baskaryan @efriis what do you think: should I remove the huggingface_hub.py and |
no we should leave them for backwards compatibility but mark them as deprecated. here's an example of how to do that for a class
|
747272b
to
36f5074
Compare
36f5074
to
e53c11f
Compare
Thank you @baskaryan ! ➡️ For the release number, I just went to the root repo and did |
libs/community/langchain_community/llms/huggingface_text_gen_inference.py
Show resolved
Hide resolved
logger = logging.getLogger(__name__) | ||
|
||
|
||
@deprecated("0.1.7", alternative="HuggingFaceEndppoint") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Endpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one last comment then lgtm
@@ -41,7 +38,7 @@ class ChatHuggingFace(BaseChatModel): | |||
Adapted from: https://python.langchain.com/docs/integrations/chat/llama2_chat | |||
""" | |||
|
|||
llm: Union[HuggingFaceTextGenInference, HuggingFaceEndpoint, HuggingFaceHub] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is also backwards incompatible, can we revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only problem is when I add this line back, it seems to confuse the deprecation manager:
Now running this script
from langchain_community.llms import HuggingFaceEndpoint
from langchain.chat_models import ChatHuggingFace
llm = HuggingFaceEndpoint(repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1")
agent = ChatHuggingFace(llm=llm)
Triggers this error:
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
[/home/ubuntu/benchmark_agents/test_frameworks.ipynb](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/test_frameworks.ipynb) Cell 1 line 5
[2](vscode-notebook-cell://ssh-remote%2Bec2/home/ubuntu/benchmark_agents/test_frameworks.ipynb#X56sdnNjb2RlLXJlbW90ZQ%3D%3D?line=1) from langchain.chat_models import ChatHuggingFace
[4](vscode-notebook-cell://ssh-remote%2Bec2/home/ubuntu/benchmark_agents/test_frameworks.ipynb#X56sdnNjb2RlLXJlbW90ZQ%3D%3D?line=3) llm = HuggingFaceEndpoint(repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1")
----> [5](vscode-notebook-cell://ssh-remote%2Bec2/home/ubuntu/benchmark_agents/test_frameworks.ipynb#X56sdnNjb2RlLXJlbW90ZQ%3D%3D?line=4) agent = ChatHuggingFace(llm=llm)
File [~/langchain_fuse_hf_endpoints/libs/community/langchain_community/chat_models/huggingface.py:50](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/langchain_fuse_hf_endpoints/libs/community/langchain_community/chat_models/huggingface.py:50), in ChatHuggingFace.__init__(self, **kwargs)
[49](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/langchain_fuse_hf_endpoints/libs/community/langchain_community/chat_models/huggingface.py:49) def __init__(self, **kwargs: Any):
---> [50](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/langchain_fuse_hf_endpoints/libs/community/langchain_community/chat_models/huggingface.py:50) super().__init__(**kwargs)
[52](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/langchain_fuse_hf_endpoints/libs/community/langchain_community/chat_models/huggingface.py:52) from transformers import AutoTokenizer
[54](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/langchain_fuse_hf_endpoints/libs/community/langchain_community/chat_models/huggingface.py:54) self._resolve_model_id()
File [~/venv/agents/lib/python3.10/site-packages/langchain_core/load/serializable.py:107](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/langchain_core/load/serializable.py:107), in Serializable.__init__(self, **kwargs)
[106](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/langchain_core/load/serializable.py:106) def __init__(self, **kwargs: Any) -> None:
--> [107](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/langchain_core/load/serializable.py:107) super().__init__(**kwargs)
[108](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/langchain_core/load/serializable.py:108) self._lc_kwargs = kwargs
File [~/venv/agents/lib/python3.10/site-packages/pydantic/v1/main.py:339](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/pydantic/v1/main.py:339), in BaseModel.__init__(__pydantic_self__, **data)
[333](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/pydantic/v1/main.py:333) """
[334](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/pydantic/v1/main.py:334) Create a new model by parsing and validating input data from keyword arguments.
[335](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/pydantic/v1/main.py:335)
[336](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/pydantic/v1/main.py:336) Raises ValidationError if the input data cannot be parsed to form a valid model.
[337](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/pydantic/v1/main.py:337) """
[338](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/pydantic/v1/main.py:338) # Uses something other than `self` the first arg to allow "self" as a settable attribute
...
[339](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/langchain_core/_api/deprecation.py:339) )
[340](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/langchain_core/_api/deprecation.py:340) else:
[341](https://vscode-remote+ssh-002dremote-002bec2.vscode-resource.vscode-cdn.net/home/ubuntu/benchmark_agents/~/venv/agents/lib/python3.10/site-packages/langchain_core/_api/deprecation.py:341) removal = f"in {removal}"
NotImplementedError: Need to determine which default deprecation schedule to use. within ?? minor releases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error seems to be triggered here and seems due to the fact that I have not setup neither pending
nor removal
argument.
@baskaryan : do you know the proper configuration I should use in my @deprecated
decorator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yea let's add a removal argument, can set removal="0.2.0"
2eaead5
to
0c6411e
Compare
@baskaryan seems like we're good to merge? |
@baskaryan thanks a lot for this review! I added follow-up on a very strange issue here: the order of the type hints in |
…ain-ai#17254) ## Description Fuse HuggingFace Endpoint-related classes into one: - [HuggingFaceHub](https://github.com/langchain-ai/langchain/blob/5ceaf784f324064b868a3cfed3fab7554173e7b3/libs/community/langchain_community/llms/huggingface_hub.py) - [HuggingFaceTextGenInference](https://github.com/langchain-ai/langchain/blob/5ceaf784f324064b868a3cfed3fab7554173e7b3/libs/community/langchain_community/llms/huggingface_text_gen_inference.py) - and [HuggingFaceEndpoint](https://github.com/langchain-ai/langchain/blob/5ceaf784f324064b868a3cfed3fab7554173e7b3/libs/community/langchain_community/llms/huggingface_endpoint.py) Are fused into - HuggingFaceEndpoint ## Issue The deduplication of classes was creating a lack of clarity, and additional effort to develop classes leads to issues like [this hack](https://github.com/langchain-ai/langchain/blob/5ceaf784f324064b868a3cfed3fab7554173e7b3/libs/community/langchain_community/llms/huggingface_endpoint.py#L159). ## Dependancies None, this removes dependancies. ## Twitter handle If you want to post about this: @AymericRoucher --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
Description
Fuse HuggingFace Endpoint-related classes into one:
Are fused into
Issue
The deduplication of classes was creating a lack of clarity, and additional effort to develop classes leads to issues like this hack.
Dependancies
None, this removes dependancies.
Twitter handle
If you want to post about this: @AymericRoucher