Commit b77175d
authored
Add: File Based Caching for
# LM Eval Caching System
## Overview
Caches base model evaluation results to speed up tests by ~30-50%. When
multiple quantization tests share the same base model and evaluation
parameters, cached results are reused instead of re-evaluating.
## Quick Start
### Enable (Default)
```bash
pytest tests/lmeval/test_lmeval.py
```
First run caches results, subsequent runs use cached results for
matching parameters.
### Disable
```bash
DISABLE_LMEVAL_CACHE=1 pytest tests/lmeval/test_lmeval.py
```
### Custom Cache Location
```bash
LMEVAL_CACHE_DIR=/tmp/cache pytest tests/lmeval/test_lmeval.py
```
## How It Works
Results are cached based on:
- Model ID (e.g., `TinyLlama/TinyLlama-1.1B-Chat-v1.0`)
- Task (e.g., `gsm8k`)
- Few-shot count
- Sample limit
- Batch size
- Model arguments (hashed)
### Cache Storage
Single CSV file: `.lmeval_cache/cache.csv`
```csv
model,task,num_fewshot,limit,batch_size,model_args_hash,result
TinyLlama/TinyLlama-1.1B-Chat-v1.0,gsm8k,5,1000,100,abc123def456,"{'results': {...}}"
```
## Usage in Tests
```python
from tests.testing_utils import cached_lm_eval_run
class TestLMEval:
@cached_lm_eval_run
def _eval_base_model(self) -> dict:
return self._eval_model(self.model)
```
## Cache Management
### Inspect Cache
```bash
cat .lmeval_cache/cache.csv
# Or with pandas
python -c "import pandas as pd; print(pd.read_csv('.lmeval_cache/cache.csv'))"
```
### Clear Cache
```bash
rm -rf .lmeval_cache/
```
### Ignore in Git
Already added to `.gitignore`:
```gitignore
.lmeval_cache/
```
## Environment Variables
| Variable | Values | Default | Description |
|----------|--------|---------|-------------|
| `DISABLE_LMEVAL_CACHE` | `1`, `true`, `yes` | disabled | Disable
caching |
| `LMEVAL_CACHE_DIR` | path | `.lmeval_cache` | Cache directory |
## Performance Example
**Without cache:** 175s total
```
Test 1 (W4A16): Base (60s) + Compressed (30s) = 90s
Test 2 (W8A8): Base (60s) + Compressed (25s) = 85s
```
**With cache:** 115s total (34% faster)
```
Test 1 (W4A16): Base (60s) + Compressed (30s) = 90s [MISS]
Test 2 (W8A8): Base (0.1s) + Compressed (25s) = 25s [HIT]
```
## Example Cache Logs
When running tests, you'll see these log messages:
**First test (cache miss):**
```
LM-Eval cache MISS: meta-llama/Meta-Llama-3-8B-Instruct/gsm8k
# ... evaluation runs ...
LM-Eval cache WRITE: meta-llama/Meta-Llama-3-8B-Instruct/gsm8k
```
**Second test with same base model (cache hit):**
```
LM-Eval cache HIT: meta-llama/Meta-Llama-3-8B-Instruct/gsm8k
# ... evaluation skipped, cached result returned ...
```
### Testing the Cache
Run two tests that share the same base model:
```bash
# Clean cache
rm -rf .lmeval_cache/
# Test 1: FP8_DYNAMIC scheme - Cache MISS
CUDA_VISIBLE_DEVICES=5 CADENCE=weekly \
TEST_DATA_FILE=tests/lmeval/configs/fp8_dynamic_per_token.yaml \
.venv/bin/python -m pytest tests/lmeval/test_lmeval.py::TestLMEval::test_lm_eval -v
# Test 2: FP8 static scheme (same base model) - Cache HIT
CUDA_VISIBLE_DEVICES=5 CADENCE=weekly \
TEST_DATA_FILE=tests/lmeval/configs/fp8_static_per_tensor.yaml \
.venv/bin/python -m pytest tests/lmeval/test_lmeval.py::TestLMEval::test_lm_eval -v
# Inspect cache
cat .lmeval_cache/cache.csv
```
Expected output shows the second test completes much faster due to
cached base model evaluation.
## Troubleshooting
### Cache Not Working
Check environment variable:
```bash
echo $DISABLE_LMEVAL_CACHE # Should be empty
```
Verify cache file exists:
```bash
ls -lh .lmeval_cache/cache.csv
```
### Cache Always Misses
Ensure exact parameter match:
- Model ID (case-sensitive)
- Task name
- All numeric parameters (fewshot, limit, batch_size)
- Model arguments
### Corrupted Cache
Simply delete and recreate:
```bash
rm .lmeval_cache/cache.csv
pytest tests/lmeval/test_lmeval.py
```
## CI/CD Integration
### GitHub Actions
```yaml
- name: Run LM Eval tests with cache
env:
LMEVAL_CACHE_DIR: ${{ runner.temp }}/lm_cache
run: pytest tests/lmeval/test_lmeval.py
```
## Design Notes
### Why CSV?
- Matches existing timing data format (`timings/*.csv`)
- Simple pandas integration
### Error Handling
Failures are logged but don't break tests - cache simply falls back to
uncached execution on any error.
Rebased version of #1900
---------
Signed-off-by: Rahul-Tuli <[email protected]>lm_eval tests (#2051)1 parent 9cb1c6d commit b77175d
3 files changed
+169
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
805 | 805 | | |
806 | 806 | | |
807 | 807 | | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
808 | 811 | | |
809 | 812 | | |
810 | 813 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
103 | 104 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
164 | 165 | | |
165 | | - | |
| 166 | + | |
166 | 167 | | |
167 | 168 | | |
168 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| 9 | + | |
7 | 10 | | |
8 | 11 | | |
9 | | - | |
| 12 | + | |
10 | 13 | | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
18 | 35 | | |
19 | 36 | | |
20 | 37 | | |
| |||
292 | 309 | | |
293 | 310 | | |
294 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
0 commit comments