Skip to content

Commit 178fa84

Browse files
Output path fix (#2993)
* fix(output_path): support direct JSON file paths * fix linting * turn off external Lm tests for now * Update help text for `output_path` --------- Co-authored-by: Baber <[email protected]>
1 parent 8be417a commit 178fa84

File tree

3 files changed

+56
-43
lines changed

3 files changed

+56
-43
lines changed

.github/workflows/unit_tests.yml

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,36 @@ jobs:
7979
path: |
8080
test_logs/*
8181
82-
testmodels:
83-
name: External LM Tests
84-
runs-on: ubuntu-latest
85-
timeout-minutes: 30
86-
steps:
87-
- name: Checkout Code
88-
uses: actions/checkout@v4
89-
- name: Set up Python 3.9
90-
uses: actions/setup-python@v5
91-
with:
92-
python-version: 3.9
93-
cache: pip
94-
cache-dependency-path: pyproject.toml
95-
96-
# Cache HuggingFace cache directory for External LM tests
97-
- name: Cache HuggingFace cache (External LM tests)
98-
uses: actions/cache@v3
99-
id: cache-hf-lm
100-
with:
101-
path: ~/.cache/huggingface
102-
key: ${{ runner.os }}-hf-cache-external-lm
103-
restore-keys: |
104-
${{ runner.os }}-hf-cache-external-lm
105-
106-
- name: Install dependencies
107-
run: |
108-
python -m pip install --upgrade pip
109-
pip install -e '.[dev,optimum,deepsparse,sparseml,api]' --extra-index-url https://download.pytorch.org/whl/cpu
110-
pip install -U transformers peft accelerate
111-
112-
- name: Test with pytest
113-
run: python -m pytest tests/models --showlocals -s -vv
114-
continue-on-error: true # Continue workflow even if tests fail
82+
# testmodels:
83+
# name: External LM Tests
84+
# runs-on: ubuntu-latest
85+
# timeout-minutes: 30
86+
# steps:
87+
# - name: Checkout Code
88+
# uses: actions/checkout@v4
89+
# - name: Set up Python 3.9
90+
# uses: actions/setup-python@v5
91+
# with:
92+
# python-version: 3.9
93+
# cache: pip
94+
# cache-dependency-path: pyproject.toml
95+
#
96+
# # Cache HuggingFace cache directory for External LM tests
97+
# - name: Cache HuggingFace cache (External LM tests)
98+
# uses: actions/cache@v3
99+
# id: cache-hf-lm
100+
# with:
101+
# path: ~/.cache/huggingface
102+
# key: ${{ runner.os }}-hf-cache-external-lm
103+
# restore-keys: |
104+
# ${{ runner.os }}-hf-cache-external-lm
105+
#
106+
# - name: Install dependencies
107+
# run: |
108+
# python -m pip install --upgrade pip
109+
# pip install -e '.[dev,optimum,deepsparse,sparseml,api]' --extra-index-url https://download.pytorch.org/whl/cpu
110+
# pip install -U transformers peft accelerate
111+
#
112+
# - name: Test with pytest
113+
# run: python -m pytest tests/models --showlocals -s -vv
114+
# continue-on-error: true # Continue workflow even if tests fail

lm_eval/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def setup_parser() -> argparse.ArgumentParser:
135135
default=None,
136136
type=str,
137137
metavar="DIR|DIR/file.json",
138-
help="The path to the output file where the result metrics will be saved. If the path is a directory and log_samples is true, the results will be saved in the directory. Else the parent directory will be used.",
138+
help="Path where result metrics will be saved. Can be either a directory or a .json file. If the path is a directory and log_samples is true, the results will be saved in the directory. Else the parent directory will be used.",
139139
)
140140
parser.add_argument(
141141
"--limit",

lm_eval/loggers/evaluation_tracker.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,21 @@ def save_results_aggregated(
229229
)
230230

231231
path = Path(self.output_path if self.output_path else Path.cwd())
232-
path = path.joinpath(self.general_config_tracker.model_name_sanitized)
233-
path.mkdir(parents=True, exist_ok=True)
234-
235232
self.date_id = datetime.now().isoformat().replace(":", "-")
236-
file_results_aggregated = path.joinpath(f"results_{self.date_id}.json")
233+
if path.suffix == ".json":
234+
path.parent.mkdir(parents=True, exist_ok=True)
235+
file_results_aggregated = path.with_name(
236+
f"{path.stem}_{self.date_id}.json"
237+
)
238+
else:
239+
path = path.joinpath(
240+
self.general_config_tracker.model_name_sanitized
241+
)
242+
path.mkdir(parents=True, exist_ok=True)
243+
file_results_aggregated = path.joinpath(
244+
f"results_{self.date_id}.json"
245+
)
246+
237247
file_results_aggregated.open("w", encoding="utf-8").write(dumped)
238248

239249
if self.api and self.push_results_to_hub:
@@ -250,12 +260,10 @@ def save_results_aggregated(
250260
)
251261
self.api.upload_file(
252262
repo_id=repo_id,
253-
path_or_fileobj=str(
254-
path.joinpath(f"results_{self.date_id}.json")
255-
),
263+
path_or_fileobj=str(file_results_aggregated),
256264
path_in_repo=os.path.join(
257265
self.general_config_tracker.model_name,
258-
f"results_{self.date_id}.json",
266+
file_results_aggregated.name,
259267
),
260268
repo_type="dataset",
261269
commit_message=f"Adding aggregated results for {self.general_config_tracker.model_name}",
@@ -290,7 +298,12 @@ def save_results_samples(
290298
eval_logger.info(f"Saving per-sample results for: {task_name}")
291299

292300
path = Path(self.output_path if self.output_path else Path.cwd())
293-
path = path.joinpath(self.general_config_tracker.model_name_sanitized)
301+
if path.suffix == ".json":
302+
path = path.parent
303+
else:
304+
path = path.joinpath(
305+
self.general_config_tracker.model_name_sanitized
306+
)
294307
path.mkdir(parents=True, exist_ok=True)
295308

296309
file_results_samples = path.joinpath(

0 commit comments

Comments
 (0)