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: Fuse HuggingFace Endpoint-related classes into one #17254

Merged
merged 26 commits into from
Feb 19, 2024

Conversation

aymeric-roucher
Copy link
Contributor

Description

Fuse HuggingFace Endpoint-related classes into one:

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.

Dependancies

None, this removes dependancies.

Twitter handle

If you want to post about this: @AymericRoucher

Copy link

vercel bot commented Feb 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain 🛑 Canceled (Inspect) Feb 19, 2024 6:36pm

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. Ɑ: models Related to LLMs or chat model modules 🤖:refactor A large refactor of a feature(s) or restructuring of many files size:XL This PR changes 500-999 lines, ignoring generated files. size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. size:XL This PR changes 500-999 lines, ignoring generated files. labels Feb 8, 2024
@aymeric-roucher
Copy link
Contributor Author

@andrewrreed @Jofthomas if you want to take a look at the PR!

@aymeric-roucher aymeric-roucher changed the title [Draft] Community: Fuse HuggingFace Endpoint-related classes into one Community: Fuse HuggingFace Endpoint-related classes into one Feb 9, 2024
@aymeric-roucher
Copy link
Contributor Author

@baskaryan @efriis what do you think: should I remove the huggingface_hub.py and
huggingface_text_gen_inference.py scripts?

@baskaryan
Copy link
Collaborator

@baskaryan @efriis what do you think: should I remove the huggingface_hub.py and huggingface_text_gen_inference.py scripts?

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

@deprecated("0.0.335", alternative="UpstashRedisByteStore")

@aymeric-roucher
Copy link
Contributor Author

Thank you @baskaryan !
I've emptied both classes and marked them with:
@deprecated("0.1.7", alternative="HuggingFaceEndppoint")

➡️ For the release number, I just went to the root repo and did current version+1, could you confirm it is the right process?

logger = logging.getLogger(__name__)


@deprecated("0.1.7", alternative="HuggingFaceEndppoint")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Endpoint

Copy link
Collaborator

@baskaryan baskaryan left a 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]
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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?

Copy link
Collaborator

@baskaryan baskaryan Feb 15, 2024

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"

@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Feb 14, 2024
@aymeric-roucher
Copy link
Contributor Author

@baskaryan seems like we're good to merge?

@baskaryan baskaryan merged commit 0d29476 into langchain-ai:master Feb 19, 2024
59 of 60 checks passed
@aymeric-roucher
Copy link
Contributor Author

@baskaryan thanks a lot for this review!

I added follow-up on a very strange issue here: the order of the type hints in llm: Union[HuggingFaceTextGenInference, HuggingFaceEndpoint, HuggingFaceHub] has an impact on the way the program runs! I don't know how to solve this yet.

haydeniw pushed a commit to haydeniw/langchain that referenced this pull request Feb 27, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm PR looks good. Use to confirm that a PR is ready for merging. Ɑ: models Related to LLMs or chat model modules 🤖:refactor A large refactor of a feature(s) or restructuring of many files size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants