Unverified Commit 178fa84d authored by Niccolò Ajroldi's avatar Niccolò Ajroldi Committed by GitHub
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: default avatarBaber <baber@hey.com>
parent 8be417a8
...@@ -79,36 +79,36 @@ jobs: ...@@ -79,36 +79,36 @@ jobs:
path: | path: |
test_logs/* test_logs/*
testmodels: # testmodels:
name: External LM Tests # name: External LM Tests
runs-on: ubuntu-latest # runs-on: ubuntu-latest
timeout-minutes: 30 # timeout-minutes: 30
steps: # steps:
- name: Checkout Code # - name: Checkout Code
uses: actions/checkout@v4 # uses: actions/checkout@v4
- name: Set up Python 3.9 # - name: Set up Python 3.9
uses: actions/setup-python@v5 # uses: actions/setup-python@v5
with: # with:
python-version: 3.9 # python-version: 3.9
cache: pip # cache: pip
cache-dependency-path: pyproject.toml # cache-dependency-path: pyproject.toml
#
# Cache HuggingFace cache directory for External LM tests # # Cache HuggingFace cache directory for External LM tests
- name: Cache HuggingFace cache (External LM tests) # - name: Cache HuggingFace cache (External LM tests)
uses: actions/cache@v3 # uses: actions/cache@v3
id: cache-hf-lm # id: cache-hf-lm
with: # with:
path: ~/.cache/huggingface # path: ~/.cache/huggingface
key: ${{ runner.os }}-hf-cache-external-lm # key: ${{ runner.os }}-hf-cache-external-lm
restore-keys: | # restore-keys: |
${{ runner.os }}-hf-cache-external-lm # ${{ runner.os }}-hf-cache-external-lm
#
- name: Install dependencies # - name: Install dependencies
run: | # run: |
python -m pip install --upgrade pip # python -m pip install --upgrade pip
pip install -e '.[dev,optimum,deepsparse,sparseml,api]' --extra-index-url https://download.pytorch.org/whl/cpu # pip install -e '.[dev,optimum,deepsparse,sparseml,api]' --extra-index-url https://download.pytorch.org/whl/cpu
pip install -U transformers peft accelerate # pip install -U transformers peft accelerate
#
- name: Test with pytest # - name: Test with pytest
run: python -m pytest tests/models --showlocals -s -vv # run: python -m pytest tests/models --showlocals -s -vv
continue-on-error: true # Continue workflow even if tests fail # continue-on-error: true # Continue workflow even if tests fail
...@@ -135,7 +135,7 @@ def setup_parser() -> argparse.ArgumentParser: ...@@ -135,7 +135,7 @@ def setup_parser() -> argparse.ArgumentParser:
default=None, default=None,
type=str, type=str,
metavar="DIR|DIR/file.json", metavar="DIR|DIR/file.json",
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.", 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.",
) )
parser.add_argument( parser.add_argument(
"--limit", "--limit",
......
...@@ -229,11 +229,21 @@ class EvaluationTracker: ...@@ -229,11 +229,21 @@ class EvaluationTracker:
) )
path = Path(self.output_path if self.output_path else Path.cwd()) path = Path(self.output_path if self.output_path else Path.cwd())
path = path.joinpath(self.general_config_tracker.model_name_sanitized)
path.mkdir(parents=True, exist_ok=True)
self.date_id = datetime.now().isoformat().replace(":", "-") self.date_id = datetime.now().isoformat().replace(":", "-")
file_results_aggregated = path.joinpath(f"results_{self.date_id}.json") if path.suffix == ".json":
path.parent.mkdir(parents=True, exist_ok=True)
file_results_aggregated = path.with_name(
f"{path.stem}_{self.date_id}.json"
)
else:
path = path.joinpath(
self.general_config_tracker.model_name_sanitized
)
path.mkdir(parents=True, exist_ok=True)
file_results_aggregated = path.joinpath(
f"results_{self.date_id}.json"
)
file_results_aggregated.open("w", encoding="utf-8").write(dumped) file_results_aggregated.open("w", encoding="utf-8").write(dumped)
if self.api and self.push_results_to_hub: if self.api and self.push_results_to_hub:
...@@ -250,12 +260,10 @@ class EvaluationTracker: ...@@ -250,12 +260,10 @@ class EvaluationTracker:
) )
self.api.upload_file( self.api.upload_file(
repo_id=repo_id, repo_id=repo_id,
path_or_fileobj=str( path_or_fileobj=str(file_results_aggregated),
path.joinpath(f"results_{self.date_id}.json")
),
path_in_repo=os.path.join( path_in_repo=os.path.join(
self.general_config_tracker.model_name, self.general_config_tracker.model_name,
f"results_{self.date_id}.json", file_results_aggregated.name,
), ),
repo_type="dataset", repo_type="dataset",
commit_message=f"Adding aggregated results for {self.general_config_tracker.model_name}", commit_message=f"Adding aggregated results for {self.general_config_tracker.model_name}",
...@@ -290,7 +298,12 @@ class EvaluationTracker: ...@@ -290,7 +298,12 @@ class EvaluationTracker:
eval_logger.info(f"Saving per-sample results for: {task_name}") eval_logger.info(f"Saving per-sample results for: {task_name}")
path = Path(self.output_path if self.output_path else Path.cwd()) path = Path(self.output_path if self.output_path else Path.cwd())
path = path.joinpath(self.general_config_tracker.model_name_sanitized) if path.suffix == ".json":
path = path.parent
else:
path = path.joinpath(
self.general_config_tracker.model_name_sanitized
)
path.mkdir(parents=True, exist_ok=True) path.mkdir(parents=True, exist_ok=True)
file_results_samples = path.joinpath( file_results_samples = path.joinpath(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment