deepset-ai / haystack-core-integrations

Additional packages (components, document stores and the likes) to extend the capabilities of Haystack version 2.0 and onwards
https://haystack.deepset.ai
Apache License 2.0
105 stars 98 forks source link

HF related warning is raised with AmazonBedrockGenerator #211

Closed bilgeyucel closed 8 months ago

bilgeyucel commented 8 months ago

Describe the bug I get a warning related to Hugging Face when using the AmazonBedrockGenerator on Colab. Everything works as expected

Warning: image

/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_token.py:88: UserWarning: 
The secret `HF_TOKEN` does not exist in your Colab secrets.
To authenticate with the Hugging Face Hub, create a token in your settings tab (https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session.
You will be able to reuse this secret in all of your notebooks.
Please note that authentication is recommended but still optional to access public models or datasets.
  warnings.warn(

There's an issue here that might be related: https://github.com/huggingface/huggingface_hub/issues/1929

To Reproduce Run the code below after installing pip install amazon-bedrock-haystack

from amazon_bedrock_haystack.generators.amazon_bedrock import AmazonBedrockGenerator

## Initialize the AmazonBedrockGenerator with an Amazon Bedrock model
bedrock_model = 'amazon.titan-text-express-v1'
generator = AmazonBedrockGenerator(model_name=bedrock_model,
                                   aws_access_key_id=aws_access_key_id,
                                   aws_secret_access_key=aws_secret_access_key,
                                   aws_region_name="us-east-1",
                                   max_length=500)

Describe your environment (please complete the following information):

anakin87 commented 8 months ago

Under the hood, AmazonBedrockGenerator is using transformers for tokenization. Lately, you always get this warning when using transformers in Colab, unless you have set the HF_TOKEN.

An unrelated example that raises the same warning:

Example ```python # ! pip install accelerate import torch from transformers import pipeline pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0", torch_dtype=torch.bfloat16, device_map="auto") # We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating messages = [ { "role": "system", "content": "You are a friendly chatbot who always responds in the style of a pirate", }, {"role": "user", "content": "How many helicopters can a human eat in one sitting?"}, ] prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95) print(outputs[0]["generated_text"]) ```

So I would say there is nothing we can do to prevent this warning...

bilgeyucel commented 8 months ago

Thanks for the explanation @anakin87. Closing this now!