Skip to content

Commit 8e7ddb9

Browse files
committed
normalize .yml files to .yaml files
both file extensions are valid, but for files that are completely under our control, might just normalize it to a single extension: .yaml. The .yaml extension seems to be preferred by the yaml spec. Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
1 parent 9050188 commit 8e7ddb9

File tree

8 files changed

+65
-7
lines changed

8 files changed

+65
-7
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ repos:
5757

5858
- repo: local
5959
hooks:
60+
- id: normalize-yaml-ext
61+
name: normalize .yml to .yaml in required places, right now only yaml files in modelopt_recipes
62+
entry: python tools/precommit/normalize_yaml_ext.py
63+
language: system
64+
files: ^modelopt_recipes/.*\.yml$
65+
6066
- id: check-modelopt-recipes
6167
name: validate modelopt recipes
6268
entry: python tools/precommit/check_modelopt_recipes.py
File renamed without changes.

modelopt_recipes/general/ptq/nvfp4_default-fp8_kv.yml renamed to modelopt_recipes/general/ptq/nvfp4_default-fp8_kv.yaml

File renamed without changes.

modelopt_recipes/general/ptq/nvfp4_experts_only-fp8_kv.yml renamed to modelopt_recipes/general/ptq/nvfp4_experts_only-fp8_kv.yaml

File renamed without changes.

modelopt_recipes/general/ptq/nvfp4_mlp_only-fp8_kv.yml renamed to modelopt_recipes/general/ptq/nvfp4_mlp_only-fp8_kv.yaml

File renamed without changes.

modelopt_recipes/general/ptq/nvfp4_omlp_only-fp8_kv.yml renamed to modelopt_recipes/general/ptq/nvfp4_omlp_only-fp8_kv.yaml

File renamed without changes.

tests/unit/recipe/test_loader.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,21 @@ def test_load_config_missing_file_raises(tmp_path):
8585

8686
def test_load_recipe_builtin_with_suffix():
8787
"""load_recipe loads a built-in PTQ recipe given the full YAML path."""
88-
recipe = load_recipe("general/ptq/fp8_default-fp8_kv.yml")
88+
recipe = load_recipe("general/ptq/fp8_default-fp8_kv.yaml")
8989
assert recipe.recipe_type == RecipeType.PTQ
9090
assert isinstance(recipe, ModelOptPTQRecipe)
9191
assert recipe.quantize
9292

9393

9494
def test_load_recipe_builtin_without_suffix():
95-
"""load_recipe resolves the .yml suffix automatically."""
95+
"""load_recipe resolves the .yaml suffix automatically."""
9696
recipe = load_recipe("general/ptq/fp8_default-fp8_kv")
9797
assert recipe.recipe_type == RecipeType.PTQ
9898

9999

100100
def test_load_recipe_builtin_description():
101101
"""The description field is loaded from the YAML metadata."""
102-
recipe = load_recipe("general/ptq/fp8_default-fp8_kv.yml")
102+
recipe = load_recipe("general/ptq/fp8_default-fp8_kv.yaml")
103103
assert isinstance(recipe.description, str)
104104
assert len(recipe.description) > 0
105105

@@ -195,10 +195,10 @@ def test_load_recipe_dir_missing_quantize_raises(tmp_path):
195195
@pytest.mark.parametrize(
196196
("yaml_path", "model_cfg_name", "kv_cfg_name"),
197197
[
198-
("general/ptq/fp8_default-fp8_kv.yml", "FP8_DEFAULT_CFG", "FP8_KV_CFG"),
199-
("general/ptq/nvfp4_default-fp8_kv.yml", "NVFP4_DEFAULT_CFG", "FP8_KV_CFG"),
200-
("general/ptq/nvfp4_mlp_only-fp8_kv.yml", "NVFP4_MLP_ONLY_CFG", "FP8_KV_CFG"),
201-
("general/ptq/nvfp4_omlp_only-fp8_kv.yml", "NVFP4_OMLP_ONLY_CFG", "FP8_KV_CFG"),
198+
("general/ptq/fp8_default-fp8_kv.yaml", "FP8_DEFAULT_CFG", "FP8_KV_CFG"),
199+
("general/ptq/nvfp4_default-fp8_kv.yaml", "NVFP4_DEFAULT_CFG", "FP8_KV_CFG"),
200+
("general/ptq/nvfp4_mlp_only-fp8_kv.yaml", "NVFP4_MLP_ONLY_CFG", "FP8_KV_CFG"),
201+
("general/ptq/nvfp4_omlp_only-fp8_kv.yaml", "NVFP4_OMLP_ONLY_CFG", "FP8_KV_CFG"),
202202
],
203203
)
204204
def test_general_ptq_yaml_matches_config_dicts(yaml_path, model_cfg_name, kv_cfg_name):
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
"""Pre-commit hook: normalize .yml to .yaml in modelopt_recipes/.
17+
18+
Standardizes YAML file extensions to ``.yaml`` for consistency. When a
19+
``.yml`` file is detected, it is renamed to ``.yaml`` and the hook exits
20+
with code 1 so the user can re-stage and commit.
21+
"""
22+
23+
from __future__ import annotations
24+
25+
import os
26+
import sys
27+
from pathlib import Path
28+
29+
30+
def main() -> int:
31+
"""Rename .yml files to .yaml, exit 1 if any were renamed."""
32+
renamed = []
33+
for f in sys.argv[1:]:
34+
path = Path(f)
35+
if path.suffix == ".yml" and path.is_file():
36+
new_path = path.with_suffix(".yaml")
37+
os.rename(path, new_path)
38+
renamed.append((path, new_path))
39+
40+
if renamed:
41+
for old, new in renamed:
42+
print(f"Renamed: {old} -> {new}")
43+
print(
44+
f"\n{len(renamed)} file(s) renamed from .yml to .yaml. "
45+
"Please re-stage the changes and commit again."
46+
)
47+
return 1
48+
return 0
49+
50+
51+
if __name__ == "__main__":
52+
raise SystemExit(main())

0 commit comments

Comments
 (0)