"""Export a tensor-only checkpoint as a Manekko model repository. Usage: python convert_checkpoint.py /path/student.ckpt --output ./export """ from __future__ import annotations import argparse import importlib.util from pathlib import Path import sys def _load_package(folder: Path): """Load local model code for direct script execution.""" name = "_manekko_export_code" spec = importlib.util.spec_from_file_location( name, folder / "__init__.py", submodule_search_locations=[str(folder)] ) module = importlib.util.module_from_spec(spec) sys.modules[name] = module spec.loader.exec_module(module) return module def main(argv=None): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("checkpoint", type=Path) parser.add_argument( "--config", type=Path, default=Path(__file__).parent / "config.json" ) parser.add_argument("--output", type=Path, required=True) args = parser.parse_args(argv) if not args.checkpoint.is_file(): parser.error(f"Checkpoint does not exist: {args.checkpoint}") if not args.config.is_file(): parser.error(f"Configuration does not exist: {args.config}") package = _load_package(Path(__file__).resolve().parent) from _manekko_export_code.modeling_manekko import load_encoder_file config = package.ManekkoConfig.from_json_file(args.config) model = package.ManekkoModel(config) state = load_encoder_file(args.checkpoint) model.load_state_dict(state, strict=True) model.eval().save_pretrained(args.output) print(f"Exported {len(state)} encoder tensors to {args.output.resolve()}") print("Upload all exported files to the matching model repository.") if __name__ == "__main__": main()