Repository: huggingface/huggingface_hub (python)

Issue:
Parameter revision is not taken into account by HfFileSystem
### Describe the bug

I created and then deleted a file from the repo. When I try to open the removed file, by passing the corresponding `revision`, I get `FileNotFoundError`.

See example below, which uses the repo: https://huggingface.co/datasets/albertvillanova/ai2_arc/commits/main

### Reproduction

```python
from huggingface_hub import HfFileSystem
fs = HfFileSystem()
with fs.open("datasets/albertvillanova/ai2_arc/ai2_arc.py", "r", encoding="utf-8", revision="f5cdce6f1179d2c391582eb32af16a742ae744d5") as f:
    data = f.read()
```

### Logs

```shell
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-6-6cd92de402ba> in <cell line: 1>()
----> 1 with fs.open("datasets/albertvillanova/ai2_arc/ai2_arc.py", "r", encoding="utf-8", revision="f5cdce6f1179d2c391582eb32af16a742ae744d5") as f:
      2     data = f.read()

7 frames
/usr/local/lib/python3.10/dist-packages/fsspec/spec.py in open(self, path, mode, block_size, cache_options, compression, **kwargs)
   1227             }
   1228             return io.TextIOWrapper(
-> 1229                 self.open(
   1230                     path,
   1231                     mode,

/usr/local/lib/python3.10/dist-packages/fsspec/spec.py in open(self, path, mode, block_size, cache_options, compression, **kwargs)
   1239         else:
   1240             ac = kwargs.pop("autocommit", not self._intrans)
-> 1241             f = self._open(
   1242                 path,
   1243                 mode=mode,

/usr/local/lib/python3.10/dist-packages/huggingface_hub/hf_file_system.py in _open(self, path, mode, revision, **kwargs)
    221         if "a" in mode:
    222             raise NotImplementedError("Appending to remote files is not yet supported.")
--> 223         return HfFileSystemFile(self, path, mode=mode, revision=revision, **kwargs)
    224 
    225     def _rm(self, path: str, revision: Optional[str] = None, **kwargs) -> None:

/usr/local/lib/python3.10/dist-packages/huggingface_hub/hf_file_system.py in __init__(self, fs, path, revision, **kwargs)
    594 class HfFileSystemFile(fsspec.spec.AbstractBufferedFile):
    595     def __init__(self, fs: HfFileSystem, path: str, revision: Optional[str] = None, **kwargs):
--> 596         super().__init__(fs, path, **kwargs)
    597         self.fs: HfFileSystem
    598 

/usr/local/lib/python3.10/dist-packages/fsspec/spec.py in __init__(self, fs, path, mode, block_size, autocommit, cache_type, cache_options, size, **kwargs)
   1595                 self.size = size
   1596             else:
-> 1597                 self.size = self.details["size"]
   1598             self.cache = caches[cache_type](
   1599                 self.blocksize, self._fetch_range, self.size, **cache_options

/usr/local/lib/python3.10/dist-packages/fsspec/spec.py in details(self)
   1608     def details(self):
   1609         if self._details is None:
-> 1610             self._details = self.fs.info(self.path)
   1611         return self._details
   1612 

/usr/local/lib/python3.10/dist-packages/huggingface_hub/hf_file_system.py in info(self, path, refresh, revision, **kwargs)
    519                 )
    520                 if not paths_info:
--> 521                     _raise_file_not_found(path, None)
    522                 path_info = paths_info[0]
    523                 root_path = HfFileSystemResolvedPath(

/usr/local/lib/python3.10/dist-packages/huggingface_hub/hf_file_system.py in _raise_file_not_found(path, err)
    668     elif isinstance(err, HFValidationError):
    669         msg = f"{path} (invalid repository id)"
--> 670     raise FileNotFoundError(msg) from err

FileNotFoundError: datasets/albertvillanova/ai2_arc/ai2_arc.py
```


### System info

```shell
- huggingface_hub version: 0.20.1
- Platform: Linux-6.1.58+-x86_64-with-glibc2.35
- Python version: 3.10.12
- Running in iPython ?: Yes
- iPython shell: Shell
- Running in notebook ?: Yes
- Running in Google Colab ?: Yes
- Token path ?: /root/.cache/huggingface/token
- Has saved token ?: False
- Configured git credential helpers: 
- FastAI: 2.7.13
- Tensorflow: 2.15.0
- Torch: 2.1.0+cu121
- Jinja2: 3.1.2
- Graphviz: 0.20.1
- Pydot: 1.4.2
- Pillow: 9.4.0
- hf_transfer: N/A
- gradio: N/A
- tensorboard: N/A
- numpy: 1.23.5
- pydantic: 1.10.13
- aiohttp: 3.9.1
- ENDPOINT: https://huggingface.co
- HF_HUB_CACHE: /root/.cache/huggingface/hub
- HF_ASSETS_CACHE: /root/.cache/huggingface/assets
- HF_TOKEN_PATH: /root/.cache/huggingface/token
- HF_HUB_OFFLINE: False
- HF_HUB_DISABLE_TELEMETRY: False
- HF_HUB_DISABLE_PROGRESS_BARS: None
- HF_HUB_DISABLE_SYMLINKS_WARNING: False
- HF_HUB_DISABLE_EXPERIMENTAL_WARNING: False
- HF_HUB_DISABLE_IMPLICIT_TOKEN: False
- HF_HUB_ENABLE_HF_TRANSFER: False
- HF_HUB_ETAG_TIMEOUT: 10
- HF_HUB_DOWNLOAD_TIMEOUT: 10
```


Pull request:
Pass revision in path to AbstractBufferedFile init
Fix #1947.

Patch:
diff --git a/src/huggingface_hub/hf_file_system.py b/src/huggingface_hub/hf_file_system.py
index 89c07fb9..424923db 100644
--- a/src/huggingface_hub/hf_file_system.py
+++ b/src/huggingface_hub/hf_file_system.py
@@ -593,9 +593,6 @@ class HfFileSystem(fsspec.AbstractFileSystem):
 
 class HfFileSystemFile(fsspec.spec.AbstractBufferedFile):
     def __init__(self, fs: HfFileSystem, path: str, revision: Optional[str] = None, **kwargs):
-        super().__init__(fs, path, **kwargs)
-        self.fs: HfFileSystem
-
         try:
             self.resolved_path = fs.resolve_path(path, revision=revision)
         except FileNotFoundError as e:
@@ -603,6 +600,8 @@ class HfFileSystemFile(fsspec.spec.AbstractBufferedFile):
                 raise FileNotFoundError(
                     f"{e}.\nMake sure the repository and revision exist before writing data."
                 ) from e
+        super().__init__(fs, self.resolved_path.unresolve(), **kwargs)
+        self.fs: HfFileSystem
 
     def __del__(self):
         if not hasattr(self, "resolved_path"):
diff --git a/src/huggingface_hub/inference/_client.py b/src/huggingface_hub/inference/_client.py
index 3a76f5ad..ecf968ed 100644
--- a/src/huggingface_hub/inference/_client.py
+++ b/src/huggingface_hub/inference/_client.py
@@ -1483,7 +1483,7 @@ class InferenceClient:
         # Remove some parameters if not a TGI server
         if not _is_tgi_server(model):
             ignored_parameters = []
-            for key in "watermark", "stop", "details", "decoder_input_details":
+            for key in "watermark", "stop", "details", "decoder_input_details", "best_of":
                 if payload["parameters"][key] is not None:
                     ignored_parameters.append(key)
                 del payload["parameters"][key]
diff --git a/src/huggingface_hub/inference/_generated/_async_client.py b/src/huggingface_hub/inference/_generated/_async_client.py
index 67a6128b..e49aa08b 100644
--- a/src/huggingface_hub/inference/_generated/_async_client.py
+++ b/src/huggingface_hub/inference/_generated/_async_client.py
@@ -1504,7 +1504,7 @@ class AsyncInferenceClient:
         # Remove some parameters if not a TGI server
         if not _is_tgi_server(model):
             ignored_parameters = []
-            for key in "watermark", "stop", "details", "decoder_input_details":
+            for key in "watermark", "stop", "details", "decoder_input_details", "best_of":
                 if payload["parameters"][key] is not None:
                     ignored_parameters.append(key)
                 del payload["parameters"][key]


Test patch:
diff --git a/tests/test_hf_file_system.py b/tests/test_hf_file_system.py
index 795b5ebd..40ffc4ad 100644
--- a/tests/test_hf_file_system.py
+++ b/tests/test_hf_file_system.py
@@ -150,6 +150,10 @@ class HfFileSystemTests(unittest.TestCase):
         with self.hffs.open(self.hf_path + "/data/text_data.txt", "r") as f:
             self.assertEqual(f.read(), "dummy text data")
 
+    def test_read_file_with_revision(self):
+        with self.hffs.open(self.hf_path + "/data/binary_data_for_pr.bin", "rb", revision="refs/pr/1") as f:
+            self.assertEqual(f.read(), b"dummy binary data on pr")
+
     def test_write_file(self):
         data = "new text data"
         with self.hffs.open(self.hf_path + "/data/new_text_data.txt", "w") as f: