Spaces:
Running
Running
Download run_fusion_eval.py from Banafo/KrokoMusci-OpenASR: direct link, hf CLI and curl.
- Browser
- Download file 2.37 kB
-
https://huggingface.co/spaces/Banafo/KrokoMusci-OpenASR/resolve/main/run_fusion_eval.py
- Command line
-
hf download hf://spaces/Banafo/KrokoMusci-OpenASR/run_fusion_eval.py
-
curl -L -o run_fusion_eval.py https://huggingface.co/spaces/Banafo/KrokoMusci-OpenASR/resolve/main/run_fusion_eval.py
2.37 kB
| """Run the original Kroko evaluator with the fusion backend.""" | |
| from hashlib import sha256 | |
| import json | |
| import os | |
| from pathlib import Path | |
| import numpy as np | |
| import onnx | |
| import run_eval | |
| from krokomusci_backend import FusionBackend, fusion_profile | |
| from preflight_model import download_release | |
| original_export = run_eval.export_bundle | |
| def export_fusion_bundle(args, hardware): | |
| bundle, metadata = original_export(args, hardware) | |
| projection = bundle / "joiner_output.npz" | |
| if not projection.exists(): | |
| root, config, _ = download_release(args.model_id, args.model_revision) | |
| decoder = onnx.load(root / config["assets"]["decoder"]) | |
| tensors = {tensor.name: tensor for tensor in decoder.graph.initializer} | |
| weight = onnx.numpy_helper.to_array(tensors["output_proj.weight"]).astype(np.float32) | |
| bias = onnx.numpy_helper.to_array(tensors["output_proj.bias"]).astype(np.float32) | |
| vocab = config["runtime_config"]["vocab_size"] | |
| dim = config["runtime_config"]["decoder_params"]["joiner_dim"] | |
| if weight.shape != (vocab, dim) or bias.shape != (vocab,) or not ( | |
| np.isfinite(weight).all() and np.isfinite(bias).all() | |
| ): | |
| raise ValueError("Invalid rescoring projection in the published Kroko decoder") | |
| temporary = bundle / "joiner_output.tmp.npz" | |
| np.savez(temporary, weight=weight, bias=bias) | |
| os.replace(temporary, projection) | |
| root = Path(__file__).resolve().parent | |
| profile, recipe = fusion_profile() | |
| profile_bytes = json.dumps(profile, sort_keys=True, separators=(",", ":")).encode() | |
| metadata["fusion"] = { | |
| "name": "KrokoMusci", | |
| "version": profile["version"], | |
| "profile_sha256": sha256(profile_bytes).hexdigest(), | |
| "speed_recipe": recipe, | |
| "packed_prefill": profile["packed_prefill"], | |
| "retain_block_cache": profile["retain_block_cache"], | |
| "calibration_sha256": "42b419732d7c9a17967b5b227b8088ca3dd830310fd2034baf199f478e077942", | |
| "models": json.loads((root / "models.json").read_text()), | |
| "timestamps": "Kroko draft timestamps", | |
| "transport": "shared audio mapping and child reply inside queue timing", | |
| } | |
| return bundle, metadata | |
| if __name__ == "__main__": | |
| run_eval.ASR = FusionBackend | |
| run_eval.export_bundle = export_fusion_bundle | |
| run_eval.main() | |