|
34 | 34 | ("vocoder", "vocoder/diffusion_pytorch_model.safetensors", "vocoder.gguf"), |
35 | 35 | ] |
36 | 36 |
|
| 37 | +# Conv kernels must not be stored BF16: the CUDA conv lowering corrupts on BF16 kernel |
| 38 | +# types (and the runtime guards this at load). Keep them F32 on disk for every target |
| 39 | +# type. |
| 40 | +KEEP_TYPES = { |
| 41 | + "transformer": ["preprocess_conv*=f32", "postprocess_conv*=f32"], |
| 42 | + "condition_encoder": ["proj.weight=f32"], |
| 43 | + "vocoder": ["dec_in_proj*=f32"], |
| 44 | +} |
| 45 | + |
| 46 | +# Config sidecars the runtime requires next to the component GGUFs. |
| 47 | +CONFIG_SIDECARS = { |
| 48 | + "language_model": "language_model/config.json", |
| 49 | + "rvq_depth_decoder": "rvq_depth_decoder/config.json", |
| 50 | + "condition_encoder": "condition_encoder/config.json", |
| 51 | + "transformer": "transformer/config.json", |
| 52 | + "vocoder": "vocoder/config.json", |
| 53 | +} |
| 54 | + |
37 | 55 |
|
38 | 56 | def parse_args() -> argparse.Namespace: |
39 | 57 | parser = argparse.ArgumentParser(description=__doc__) |
@@ -117,6 +135,7 @@ def write_variant_spec(args: argparse.Namespace) -> tempfile.TemporaryDirectory[ |
117 | 135 |
|
118 | 136 | output_by_name = {name: output_name(args, component) for name, _input, _base in COMPONENTS for component in [next(c for c in COMPONENTS if c[0] == name)]} |
119 | 137 | gguf_source = next(source for source in spec["sources"] if source["format"] == "gguf") |
| 138 | + gguf_source.setdefault("tensors", {}) |
120 | 139 | gguf_source["tensors"]["language_model_weights"] = f"model:{output_by_name['language_model']}" |
121 | 140 | gguf_source["tensors"]["depth_decoder_weights"] = f"model:{output_by_name['rvq_depth_decoder']}" |
122 | 141 | gguf_source["tensors"]["condition_encoder_weights"] = f"model:{output_by_name['condition_encoder']}" |
@@ -151,11 +170,22 @@ def run_conversion(args: argparse.Namespace, component: tuple[str, str, str]) -> |
151 | 170 | "--model-spec", |
152 | 171 | str(args.model_spec), |
153 | 172 | "--no-sidecars", |
| 173 | + # The runtime opens component GGUFs by filename rather than through spec tensor |
| 174 | + # ids, and the spec's gguf source does not yet match audiocpp_gguf's |
| 175 | + # source-matching rules, so conversion proceeds without a matching package spec. |
| 176 | + "--allow-missing-model-spec", |
154 | 177 | ] |
| 178 | + for keep in KEEP_TYPES.get(name, []): |
| 179 | + cmd.extend(["--keep-type", keep]) |
155 | 180 | if args.overwrite: |
156 | 181 | cmd.append("--overwrite") |
157 | 182 | print("[convert]", name, "->", output_path, flush=True) |
158 | 183 | subprocess.run(cmd, cwd=REPO_ROOT, check=True) |
| 184 | + sidecar = CONFIG_SIDECARS.get(name) |
| 185 | + if sidecar is not None: |
| 186 | + config_dir = Path(args.output) / "config" |
| 187 | + config_dir.mkdir(parents=True, exist_ok=True) |
| 188 | + shutil.copyfile(Path(args.source) / sidecar, config_dir / f"{name}.json") |
159 | 189 |
|
160 | 190 |
|
161 | 191 | def main() -> None: |
|
0 commit comments