#!/usr/bin/env python3 """Convert pinned Bark 3.0 Plus weights for the native Parakeet-TDT runtime. Decode the official bark-levels-v3 data without executing downloaded Python. The entropy/level reconstruction follows Conway Research's CC-BY-4.0 bark_loader.py; see the retained NOTICE. Requires numpy, constriction==0.5.0 and safetensors. Runtime inference has no Python/ANS dependency. """ import argparse import hashlib import json import lzma import math import os from pathlib import Path import shutil import subprocess import tempfile from dataclasses import dataclass import numpy as np from convert_phonon2 import (compensate_batch_norm, compensate_projection, lossless_f16_tensors, mixed_q8_tensors, read_exact, sha256) from convert_underdog_bark3 import package_spec as pro_package_spec, validate_config SOURCE_REPO = "ConwayResearch/Underdog-Bark-3.0-Plus" SOURCE_REVISION = "d4fab2f8b95681e5ad3cfb4e8c5f4e0c009b3deb" SOURCE_SHA256 = "fdd9f1052e4fdead07d71e8cd2138813eb0c209fd6ff8b1b6f47737e1e501857" BASE_REPO = "nvidia/parakeet-tdt-0.6b-v3" BASE_REVISION = "541d1f99c6b0c3cd0b11a95167540bb8edefd82b" VARIANT = "underdog_bark3_plus" SIDECARS = ("processor_config.json", "tokenizer.json", "tokenizer_config.json", "generation_config.json") BASE_SHA256 = { "config.json": "e747b85e1bdfd300c8b8ac63bac8dd5221f8fe9bc275b48d06c735fcd6971b6e", "processor_config.json": "8346a93a3b987fa1dec57a78f045cd0817d21786589a5a096b41a57a446fd1d7", "tokenizer.json": "bd321b096832a3f270bd3b2a88823957920f1a5c5ada71114a26ea729d0cbe91", "tokenizer_config.json": "0b2fe0037599ee335f0b972fa682bf0ece74e4ccfec755cb7daa3405d3d3e874", "generation_config.json": "b141de6ec6d7f982ece13f98f604e3fe1807ea9c0e839185d0ab7064604209d0", } @dataclass(frozen=True) class BarkPackedProfile: source_repo: str source_revision: str source_sha256: str variant: str display_name: str docs: str bf16_f32_prefixes: tuple[str, ...] = () PLUS_PROFILE = BarkPackedProfile(SOURCE_REPO, SOURCE_REVISION, SOURCE_SHA256, VARIANT, "Underdog Bark 3.0 Plus", "docs/models/underdog_bark3.md") def unpack_blob(data, compressed, size): if compressed: decoder = lzma.LZMADecompressor() data = decoder.decompress(data, max_length=size + 1) if not decoder.eof or decoder.unused_data: raise ValueError("invalid or oversized LZMA side blob") if len(data) != size: raise ValueError("incorrect side blob size") return data def decode_record(entry, blobs): """Return the same values/dtypes as the official NumPy unpacker.""" import constriction shape = entry["shape"] if not isinstance(shape, list) or len(shape) > 4 or any(type(n) is not int or n <= 0 for n in shape): raise ValueError("invalid tensor shape") count = math.prod(shape) if count > 64 * 1024 * 1024: raise ValueError("tensor exceeds the supported architecture") kind = entry["k"] if kind == "raw": dtype = {"torch.int64": " levels_count, -values, values).reshape(shape) if kind not in ("ansint5", "ansint6"): raise ValueError("unsupported ANS record kind") bits = int(kind[-1]) scales = np.frombuffer(unpack_blob(blobs["s"], entry.get("zs", False), rows * 2), dtype="