Skip to content

Commit 7cec62e

Browse files
Protect hf token (#309)
1 parent f12f642 commit 7cec62e

12 files changed

+207
-157
lines changed

.github/workflows/test_cli_cpu_py_txi.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ jobs:
4343

4444
- name: Install requirements
4545
run: |
46-
pip install --upgrade pip
47-
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
48-
pip install -e .[testing,py-txi] git+https://github.com/IlyasMoutawwakil/py-txi.git
46+
pip install uv
47+
uv pip install --upgrade pip
48+
uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
49+
uv pip install -e .[testing,py-txi] git+https://github.com/IlyasMoutawwakil/py-txi.git
50+
env:
51+
UV_SYSTEM_PYTHON: 1
4952

5053
- name: Run tests
5154
run: pytest tests/test_cli.py -s -k "cli and cpu and py_txi"

.github/workflows/test_cli_cuda_py_txi.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,22 @@ jobs:
4444

4545
- name: Install requirements
4646
run: |
47-
pip install --upgrade pip
48-
pip install -e .[testing,py-txi] git+https://github.com/IlyasMoutawwakil/py-txi.git
47+
pip install uv
48+
uv pip install --upgrade pip
49+
uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
50+
uv pip install -e .[testing,py-txi] git+https://github.com/IlyasMoutawwakil/py-txi.git
51+
env:
52+
UV_SYSTEM_PYTHON: 1
4953

5054
- name: Run tests
51-
run: pytest tests/test_cli.py -x -s -k "cli and cuda and py_txi"
55+
run: |
56+
FORCE_SEQUENTIAL=1 pytest tests/test_cli.py -x -s -k "cli and cuda and py_txi"
5257
5358
- if: ${{
5459
(github.event_name == 'push') ||
5560
(github.event_name == 'workflow_dispatch') ||
5661
contains( github.event.pull_request.labels.*.name, 'examples')
5762
}}
5863
name: Run examples
59-
run: pytest tests/test_examples.py -x -s -k "cli and cuda and (tgi or tei)"
64+
run: |
65+
FORCE_SEQUENTIAL=1 pytest tests/test_examples.py -x -s -k "cli and cuda and (tgi or tei)"

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ Optimum-Benchmark is continuously and intensively tested on a variety of devices
5050

5151
[![CLI_CPU_IPEX](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cpu_ipex.yaml/badge.svg)](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cpu_ipex.yaml)
5252
[![CLI_CPU_LLAMA_CPP](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cpu_llama_cpp.yaml/badge.svg)](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cpu_llama_cpp.yaml)
53-
[![CLI_CPU_NEURAL_COMPRESSOR](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cpu_neural_compressor.yaml/badge.svg)](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cpu_neural_compressor.yaml)
5453
[![CLI_CPU_ONNXRUNTIME](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cpu_onnxruntime.yaml/badge.svg)](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cpu_onnxruntime.yaml)
5554
[![CLI_CPU_OPENVINO](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cpu_openvino.yaml/badge.svg)](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cpu_openvino.yaml)
5655
[![CLI_CPU_PYTORCH](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cpu_pytorch.yaml/badge.svg)](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cpu_pytorch.yaml)
@@ -61,7 +60,6 @@ Optimum-Benchmark is continuously and intensively tested on a variety of devices
6160
[![CLI_CUDA_TENSORRT_LLM](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cuda_tensorrt_llm.yaml/badge.svg)](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cuda_tensorrt_llm.yaml)
6261
[![CLI_CUDA_TORCH_ORT](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cuda_torch_ort.yaml/badge.svg)](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cuda_torch_ort.yaml)
6362
[![CLI_CUDA_VLLM](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cuda_vllm.yaml/badge.svg)](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_cuda_vllm.yaml)
64-
[![CLI_ENERGY_STAR](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_energy_star.yaml/badge.svg)](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_energy_star.yaml)
6563
[![CLI_MISC](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_misc.yaml/badge.svg)](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_misc.yaml)
6664
[![CLI_ROCM_PYTORCH](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_rocm_pytorch.yaml/badge.svg)](https://github.com/huggingface/optimum-benchmark/actions/workflows/test_cli_rocm_pytorch.yaml)
6765

@@ -100,10 +98,9 @@ Depending on the backends you want to use, you can install `optimum-benchmark` w
10098
- OnnxRuntime: `pip install optimum-benchmark[onnxruntime]`
10199
- TensorRT-LLM: `pip install optimum-benchmark[tensorrt-llm]`
102100
- OnnxRuntime-GPU: `pip install optimum-benchmark[onnxruntime-gpu]`
103-
- Neural Compressor: `pip install optimum-benchmark[neural-compressor]`
104-
- Py-TXI: `pip install optimum-benchmark[py-txi]`
105-
- IPEX: `pip install optimum-benchmark[ipex]`
101+
- Py-TXI (TGI & TEI): `pip install optimum-benchmark[py-txi]`
106102
- vLLM: `pip install optimum-benchmark[vllm]`
103+
- IPEX: `pip install optimum-benchmark[ipex]`
107104

108105
We also support the following extra extra dependencies:
109106

@@ -144,9 +141,6 @@ if __name__ == "__main__":
144141
)
145142
benchmark_report = Benchmark.launch(benchmark_config)
146143

147-
# log the benchmark in terminal
148-
benchmark_report.log() # or print(benchmark_report)
149-
150144
# convert artifacts to a dictionary or dataframe
151145
benchmark_config.to_dict() # or benchmark_config.to_dataframe()
152146

@@ -175,15 +169,17 @@ If you're on VSCode, you can hover over the configuration classes to see the ava
175169
You can also run a benchmark using the command line by specifying the configuration directory and the configuration name. Both arguments are mandatory for [`hydra`](https://hydra.cc/). `--config-dir` is the directory where the configuration files are stored and `--config-name` is the name of the configuration file without its `.yaml` extension.
176170

177171
```bash
178-
optimum-benchmark --config-dir examples/ --config-name pytorch_bert
172+
optimum-benchmark --config-dir examples/ --config-name cuda_pytorch_bert
179173
```
180174

181-
This will run the benchmark using the configuration in [`examples/pytorch_bert.yaml`](examples/pytorch_bert.yaml) and store the results in `runs/pytorch_bert`.
175+
This will run the benchmark using the configuration in [`examples/cuda_pytorch_bert.yaml`](examples/cuda_pytorch_bert.yaml) and store the results in `runs/cuda_pytorch_bert`.
182176

183177
The resulting files are :
184178

185179
- `benchmark_config.json` which contains the configuration used for the benchmark, including the backend, launcher, scenario and the environment in which the benchmark was run.
186180
- `benchmark_report.json` which contains a full report of the benchmark's results, like latency measurements, memory usage, energy consumption, etc.
181+
- `benchmark_report.txt` which contains a detailed report of the benchmark's results, in the same format they were logged.
182+
- `benchmark_report.md` which contains a detailed report of the benchmark's results, in markdown format.
187183
- `benchmark.json` contains both the report and the configuration in a single file.
188184
- `benchmark.log` contains the logs of the benchmark run.
189185

@@ -309,9 +305,7 @@ For more information on the features of each backend, you can check their respec
309305
- [PyTorchConfig](optimum_benchmark/backends/pytorch/config.py)
310306
- [ORTConfig](optimum_benchmark/backends/onnxruntime/config.py)
311307
- [TorchORTConfig](optimum_benchmark/backends/torch_ort/config.py)
312-
- [LLMSwarmConfig](optimum_benchmark/backends/llm_swarm/config.py)
313308
- [TRTLLMConfig](optimum_benchmark/backends/tensorrt_llm/config.py)
314-
- [INCConfig](optimum_benchmark/backends/neural_compressor/config.py)
315309

316310
</details>
317311

examples/cuda_pytorch_bert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defaults:
66
- _base_
77
- _self_
88

9-
name: pytorch_bert
9+
name: cuda_pytorch_bert
1010

1111
launcher:
1212
device_isolation: true

optimum_benchmark/backends/config.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class BackendConfig(ABC):
2222
version: str
2323
_target_: str
2424

25+
model: Optional[str] = None
26+
processor: Optional[str] = None
27+
2528
task: Optional[str] = None
2629
library: Optional[str] = None
2730
model_type: Optional[str] = None
2831

29-
model: Optional[str] = None
30-
processor: Optional[str] = None
31-
3232
device: Optional[str] = None
3333
# we use a string here instead of a list
3434
# because it's easier to pass in a yaml or from cli
@@ -48,30 +48,44 @@ def __post_init__(self):
4848
if self.model is None:
4949
raise ValueError("`model` must be specified.")
5050

51+
if self.model_kwargs.get("token", None) is not None:
52+
LOGGER.info(
53+
"You have passed an argument `token` to `model_kwargs`. This is dangerous as the config cannot do encryption to protect it. "
54+
"We will proceed to registering `token` in the environment as `HF_TOKEN` to avoid saving it or pushing it to the hub by mistake."
55+
)
56+
os.environ["HF_TOKEN"] = self.model_kwargs.pop("token")
57+
5158
if self.processor is None:
5259
self.processor = self.model
5360

54-
# TODO: add cache_dir, token, etc. to these methods
61+
if not self.processor_kwargs:
62+
self.processor_kwargs = self.model_kwargs
63+
5564
if self.library is None:
5665
self.library = infer_library_from_model_name_or_path(
5766
model_name_or_path=self.model,
58-
token=self.model_kwargs.get("token", None),
5967
revision=self.model_kwargs.get("revision", None),
68+
cache_dir=self.model_kwargs.get("cache_dir", None),
69+
)
70+
71+
if self.library not in ["transformers", "diffusers", "timm", "llama_cpp"]:
72+
raise ValueError(
73+
f"`library` must be either `transformers`, `diffusers`, `timm` or `llama_cpp`, but got {self.library}"
6074
)
6175

6276
if self.task is None:
6377
self.task = infer_task_from_model_name_or_path(
6478
model_name_or_path=self.model,
65-
token=self.model_kwargs.get("token", None),
6679
revision=self.model_kwargs.get("revision", None),
80+
cache_dir=self.model_kwargs.get("cache_dir", None),
6781
library_name=self.library,
6882
)
6983

7084
if self.model_type is None:
7185
self.model_type = infer_model_type_from_model_name_or_path(
7286
model_name_or_path=self.model,
73-
token=self.model_kwargs.get("token", None),
7487
revision=self.model_kwargs.get("revision", None),
88+
cache_dir=self.model_kwargs.get("cache_dir", None),
7589
library_name=self.library,
7690
)
7791

@@ -103,11 +117,6 @@ def __post_init__(self):
103117
else:
104118
raise RuntimeError("CUDA device is only supported on systems with NVIDIA or ROCm drivers.")
105119

106-
if self.library not in ["transformers", "diffusers", "timm", "llama_cpp"]:
107-
raise ValueError(
108-
f"`library` must be either `transformers`, `diffusers`, `timm` or `llama_cpp`, but got {self.library}"
109-
)
110-
111120
if self.inter_op_num_threads is not None:
112121
if self.inter_op_num_threads == -1:
113122
self.inter_op_num_threads = cpu_count()

0 commit comments

Comments
 (0)