-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
How do fix GPT2 Tokenizer error in Langchain map_reduce (LLama2)? #9273
Comments
🤖 Hello, The error you're encountering is due to the fact that the GPT2 tokenizer is trying to download the necessary files from HuggingFace's model hub, which is not accessible in your environment. To resolve this issue, you can download the necessary tokenizer files in an environment where you have access to HuggingFace's model hub, then transfer these files to your AWS Sagemaker environment. Once the files are in your environment, you can set the path of the GPT2 tokenizer to the local directory where you stored the tokenizer files. However, the LangChain framework, as shown in your provided context, uses the OpenAI API for language model operations and does not directly interact with the GPT2 tokenizer. The tokenizer is typically used for preprocessing the input data before it is fed into the language model. If you are experiencing issues with the GPT2 tokenizer, it might be related to the specific way you are using the LangChain framework or the specific configuration of your AWS Sagemaker environment. If you are using a custom language model that requires the GPT2 tokenizer, you might need to modify the LangChain framework to support this. This could involve modifying the Here is the code for the def _get_encoding_model(self) -> Tuple[str, tiktoken.Encoding]:
tiktoken_ = _import_tiktoken()
if self.tiktoken_model_name is not None:
model = self.tiktoken_model_name
else:
model = self.model_name
if model == "gpt-3.5-turbo":
# gpt-3.5-turbo may change over time.
# Returning num tokens assuming gpt-3.5-turbo-0301.
model = "gpt-3.5-turbo-0301"
elif model == "gpt-4":
# gpt-4 may change over time.
# Returning num tokens assuming gpt-4-0314.
model = "gpt-4-0314"
# Returns the number of tokens used by a list of messages.
try:
encoding = tiktoken_.encoding_for_model(model)
except KeyError:
logger.warning("Warning: model not found. Using cl100k_base encoding.")
model = "cl100k_base"
encoding = tiktoken_.get_encoding(model)
return model, encoding You can find this method in the Please provide more specific information about the error you are experiencing and how you are using the LangChain framework for more detailed assistance. I hope this helps! Let me know if you have any other questions. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
@dosu-bot I'm using the Llama2 jumpstart model in sagemaker (model name: Llama-2-13b-chat | model_id: meta-textgeneration-llama-2-13b-f) setup as an inference endpoint. Outside of the sagemaker environment, I'm running my langchain summarize chain with map_reduce.
I dont have access to openai or huggingface in my environment. I do have the gpt2 model downloaded locally. How do I supply this parameter to the map_reduce function thats throwing the error? |
Hi @dm-2111 |
🤖 Hello, Based on the information you've provided and the context from the LangChain repository, it seems like you're trying to use a locally downloaded GPT2 model with the LangChain's map_reduce function. Currently, the LangChain framework does not directly support the use of locally downloaded models in its map_reduce function. The map_reduce function in LangChain is designed to work with language models that are hosted on a server and accessed via an API endpoint, such as the AWS Sagemaker endpoint you're using. However, you can modify the LangChain code to support locally downloaded models. Here's a rough idea of how you can do this:
from langchain.llms import LLM
class LocalGPT2(LLM):
def __init__(self, model_path, **kwargs):
super().__init__(**kwargs)
self.model = GPT2Model.from_pretrained(model_path)
def __call__(self, text, **kwargs):
# Use your GPT2 model to generate a response
response = self.model.generate(text, **kwargs)
return response
llm = LocalGPT2(model_path="/path/to/your/model/gpt2-model.bin")
chain = load_summarize_chain(llm, chain_type="map_reduce")
chain.run(docs) Please note that this is a rough idea and you might need to adjust the code to fit your specific needs. Also, this approach requires a good understanding of the LangChain codebase and the workings of the GPT2 model. I hope this helps! If you have any other questions, feel free to ask. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Hi, @dm-2111, I'm helping the LangChain team manage their backlog and am marking this issue as stale. From what I understand, you encountered a GPT2 tokenizer error when running a Langchain summarize chain with chain_type="map_reduce" in the Llama2 model. You were unable to load the tokenizer for 'gpt2' from 'https://huggingface.co/models' and were seeking a way to set the gpt2 tokenizer in a local directory. Suggestions were provided to download the necessary tokenizer files in an environment with access to HuggingFace's model hub and transfer them to the AWS Sagemaker environment, as well as to modify the LangChain code to support locally downloaded models. Additionally, it was mentioned that the LangChain framework does not directly support the use of locally downloaded models in its map_reduce function. Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, please let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days. Thank you for your understanding and cooperation. If you have any further questions or need assistance, feel free to reach out. |
This answer appears to be wrong. First, it should be Second, running this suggested solution creates an error: 'TypeError: Can't instantiate abstract class LocalGPT2 with abstract methods _call, _llm_type'. Please provide a working solution for using a local version of the GPT2-model instead of attempting to download it from the internet, in cases when an internet connection is not available. |
System Info
I'm using AWS Sagemaker Jumpstart model for Llama2 13b: meta-textgeneration-llama-2-13b-f
On running a Langchain summarize chain with chain_type="map_reduce" I get the below error. Other chain types (refine, stuff) work without issues. I do not have access to https://huggingface.co/ from my environment. Is there a way to set the gpt2 tokenizer in a local dir?
Error:
Who can help?
No response
Information
Related Components
Reproduction
Provided above
Expected behavior
Provided above
The text was updated successfully, but these errors were encountered: