Repository: deepset-ai/haystack

Issue:
Private (gen) model from HF fails running in promptnode
**Describe the bug**
(generative) private models on huggingface can't be run, since they append `use_auth_token` to the model kwargs which is not expected. 
That means:
- using private models from HF within the Promptnode does not work 
- if you configure an auth token and you have a public model, your will be able to initialize, but not run the pipeline (quite an edge case) 

**Error message**
```
ValueError: The following `model_kwargs` are not used by the model: ['use_auth_token'] (note: typos in the generate arguments will also show up in this list)
```

**Expected behavior**
Send token to HF for download but not inject args as model_kwargs

**Additional context**
Add any other context about the problem here, like document types / preprocessing steps / settings of reader etc.

**To Reproduce**
```
from haystack.nodes import PromptNode, PromptTemplate
from haystack import Document


# Works
pn_works = PromptNode(
    default_prompt_template=PromptTemplate(prompt="deepset/summarization"),
    model_name_or_path="google/flan-t5-base",
)
# retunrs successful
pn_works.run("That works!",documents=[Document(content="asdf")])


# Fails
pn_fails = PromptNode(
    default_prompt_template=PromptTemplate(prompt="deepset/summarization"),
    model_name_or_path="google/flan-t5-base",
    use_auth_token="<any-hf-token>",
)
# retunrs successful
pn_fails.run("Oh no!",documents=[Document(content="asdf")])
```

**FAQ Check**
- [x] Have you had a look at [our new FAQ page](https://docs.haystack.deepset.ai/docs/faq)?

**System:**
 - N/A


Discussion:
Additional information. I tested this with a private flan clone

Soo there are actually two issues now (I think). If you try to use a private model with  `use_auth_token` you are getting the error that the model is not listed (transformers changed the argument to `token`).
If we take one more step (assuming that we fixed the argument),  you will most likely still get the unexpected argument error. 

So we need to have two fixes:
- adjust the paramter to token (or map argument to token)
- fix run method to not pass the token to the inference call 


@ArzelaAscoIi I am working on a fix.

I'm experimenting with two use cases:
- use a public model and pass a HF token (that should be ignored)
- use a private model and pass a HF token (that should be used)

```python
from haystack.nodes import PromptNode, PromptTemplate
from haystack import Document

pn_unused_auth_token = PromptNode(
    default_prompt_template=PromptTemplate(prompt="deepset/summarization"),
    model_name_or_path="google/flan-t5-base",
    use_auth_token="UNUSED-HF-TOKEN",
)

res=pn_unused_auth_token.run("Oh no!",documents=[Document(content="Some text to summarize")])


pn_private = PromptNode(
    default_prompt_template=PromptTemplate(prompt="deepset/summarization"),
    model_name_or_path="anakin87/flan-t5-base-clone",
    use_auth_token="REAL-HF-TOKEN",
)

res=pn_private.run("Oh no!",documents=[Document(content="Some text to summarize")])
```

**In case my fix makes the previous code correctly run, can we assume that the bug has been fixed?**
Or is there some scenario that I haven't considered?

Yes. If both scenarios work as expected it would cover all cases we need :) Thanks!

Resolving patch:
diff --git a/haystack/nodes/prompt/invocation_layer/hugging_face.py b/haystack/nodes/prompt/invocation_layer/hugging_face.py
--- a/haystack/nodes/prompt/invocation_layer/hugging_face.py
+++ b/haystack/nodes/prompt/invocation_layer/hugging_face.py
@@ -183,7 +183,8 @@ def _prepare_pipeline_kwargs(self, **kwargs) -> Dict[str, Any]:
         trust_remote_code = kwargs.get("trust_remote_code", False)
         hub_kwargs = {
             "revision": kwargs.get("revision", None),
-            "use_auth_token": kwargs.get("use_auth_token", None),
+            # use_auth_token is no longer used in HuggingFace pipelines. We convert it to token
+            "token": kwargs.get("use_auth_token", None),
             "trust_remote_code": trust_remote_code,
         }
         model_kwargs = kwargs.get("model_kwargs", {})


Test patch:
diff --git a/test/prompt/invocation_layer/test_hugging_face.py b/test/prompt/invocation_layer/test_hugging_face.py
--- a/test/prompt/invocation_layer/test_hugging_face.py
+++ b/test/prompt/invocation_layer/test_hugging_face.py
@@ -59,6 +59,9 @@ def test_constructor_with_model_name_only(mock_pipeline, mock_get_task):
     assert kwargs["task"] == "text2text-generation"
     assert kwargs["model"] == "google/flan-t5-base"
 
+    # use_auth_token is no longer used in HuggingFace pipelines and should never be passed
+    assert "use_auth_token" not in kwargs
+
     # no matter what kwargs we pass or don't pass, there are always 14 predefined kwargs passed to the pipeline
     assert len(kwargs) == 14
 
@@ -76,7 +79,7 @@ def test_constructor_with_model_name_only(mock_pipeline, mock_get_task):
         "pipeline_class",
         "use_fast",
         "revision",
-        "use_auth_token",
+        "token",
         "trust_remote_code",
     ]