1+ name : Benchmark v2 Framework
2+
3+ on :
4+ workflow_call :
5+ inputs :
6+ model_id :
7+ description : ' Model ID to benchmark (e.g., meta-llama/Llama-2-7b-hf)'
8+ required : false
9+ type : string
10+ default : ' '
11+ warmup_iterations :
12+ description : ' Number of warmup iterations'
13+ required : false
14+ type : number
15+ default : 3
16+ measurement_iterations :
17+ description : ' Number of measurement iterations'
18+ required : false
19+ type : number
20+ default : 5
21+ num_tokens_to_generate :
22+ description : ' Number of tokens to generate'
23+ required : false
24+ type : number
25+ default : 100
26+ commit_sha :
27+ description : ' Commit SHA to benchmark'
28+ required : false
29+ type : string
30+ default : ' '
31+
32+ env :
33+ HF_HOME : /mnt/cache
34+ TRANSFORMERS_IS_CI : yes
35+ # For gated repositories, we still need to agree to share information on the Hub repo. page in order to get access.
36+ # This token is created under the bot `hf-transformers-bot`.
37+ HF_HUB_READ_TOKEN : ${{ secrets.HF_HUB_READ_TOKEN }}
38+
39+ jobs :
40+ benchmark-v2 :
41+ name : Benchmark v2
42+ strategy :
43+ matrix :
44+ # Use GPU-enabled runners for accurate benchmarking
45+ group : [aws-g5-4xlarge-cache]
46+ runs-on :
47+ group : ${{ matrix.group }}
48+ container :
49+ image : huggingface/transformers-pytorch-gpu
50+ options : --gpus all --privileged --ipc host --shm-size "16gb"
51+ steps :
52+ - name : Get repo
53+ uses : actions/checkout@v4
54+ with :
55+ ref : ${{ inputs.commit_sha || github.sha }}
56+
57+ - name : Update clone
58+ if : inputs.commit_sha
59+ run : |
60+ git fetch && git checkout ${{ inputs.commit_sha }}
61+
62+ - name : Install benchmark dependencies
63+ working-directory : benchmark_v2
64+ run : |
65+ python3 -m pip install -r requirements.txt
66+
67+ - name : Reinstall transformers in edit mode
68+ run : |
69+ python3 -m pip uninstall -y transformers
70+ python3 -m pip install -e ".[torch]"
71+
72+ - name : Show installed libraries and their versions
73+ run : |
74+ python3 -m pip list
75+ python3 -c "import torch; print(f'PyTorch version: {torch.__version__}')"
76+ python3 -c "import torch; print(f'CUDA available: {torch.cuda.is_available()}')"
77+ python3 -c "import torch; print(f'CUDA device count: {torch.cuda.device_count()}')" || true
78+ nvidia-smi || true
79+
80+ - name : Prepare benchmark arguments
81+ id : prepare-args
82+ run : |
83+ args="--log-level INFO"
84+
85+ # Add model ID if specified
86+ if [ -n "${{ inputs.model_id }}" ]; then
87+ args="$args --model-id '${{ inputs.model_id }}'"
88+ fi
89+
90+ # Add iterations
91+ args="$args --warmup-iterations ${{ inputs.warmup_iterations }}"
92+ args="$args --measurement-iterations ${{ inputs.measurement_iterations }}"
93+ args="$args --num-tokens-to-generate ${{ inputs.num_tokens_to_generate }}"
94+
95+ # Add commit ID if available
96+ if [ -n "${{ inputs.commit_sha }}" ]; then
97+ args="$args --commit-id '${{ inputs.commit_sha }}'"
98+ elif [ -n "${{ github.sha }}" ]; then
99+ args="$args --commit-id '${{ github.sha }}'"
100+ fi
101+
102+ echo "benchmark_args=$args" >> $GITHUB_OUTPUT
103+ echo "Benchmark arguments: $args"
104+
105+ - name : Run benchmark v2
106+ working-directory : benchmark_v2
107+ run : |
108+ echo "Running benchmark with args: ${{ steps.prepare-args.outputs.benchmark_args }}"
109+ python3 run_benchmarks.py ${{ steps.prepare-args.outputs.benchmark_args }}
110+ env :
111+ HF_TOKEN : ${{ secrets.HF_HUB_READ_TOKEN }}
0 commit comments