Datasets:
Download scripts/normalize_lalamo_config.py from yamahei21/uzu-quant-kit: direct link, hf CLI and curl.
- Browser
- Download file 1.76 kB
-
https://huggingface.co/datasets/yamahei21/uzu-quant-kit/resolve/main/scripts/normalize_lalamo_config.py
- Command line
-
hf download hf://datasets/yamahei21/uzu-quant-kit/scripts/normalize_lalamo_config.py
-
curl -L -o normalize_lalamo_config.py https://huggingface.co/datasets/yamahei21/uzu-quant-kit/resolve/main/scripts/normalize_lalamo_config.py
1.76 kB
| #!/usr/bin/env python3 | |
| """Make a lalamo-generated config.json loadable by uzu. | |
| uzu config structs are generated by `#[uzu_config]`, which applies: | |
| * `#[serde(deny_unknown_fields)]` on every config struct | |
| * a required deserializer on every field, so `Option<T>` must still be present | |
| lalamo emits a newer token_codec schema, so: | |
| * drop fields uzu does not know (`response_format`, ...) | |
| * add missing nullable fields (`output_parser_regex`, `end_of_thinking_tag`) | |
| Usage: | |
| python scripts/normalize_lalamo_config.py /path/to/model_dir [more_dirs...] | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| REQUIRED = ("output_parser_regex", "end_of_thinking_tag") | |
| UNSUPPORTED = ("response_format", "reasoning_effort") | |
| def normalize(output_dir: Path) -> bool: | |
| path = output_dir / "config.json" | |
| config = json.loads(path.read_text()) | |
| token_codec = config.get("token_codec_config") | |
| if token_codec is None: | |
| print(f"{output_dir}: no token_codec_config, skipped") | |
| return False | |
| removed = [key for key in UNSUPPORTED if token_codec.pop(key, None) is not None] | |
| added = [key for key in REQUIRED if key not in token_codec] | |
| for key in added: | |
| token_codec[key] = None | |
| if not removed and not added: | |
| print(f"{output_dir}: already normalized") | |
| return False | |
| path.write_text(json.dumps(config, indent=2) + "\n") | |
| print(f"{output_dir}: removed={removed or '[]'} added={added or '[]'}") | |
| return True | |
| def main() -> None: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("dirs", type=Path, nargs="+") | |
| args = parser.parse_args() | |
| for directory in args.dirs: | |
| normalize(directory) | |
| if __name__ == "__main__": | |
| main() | |