frames rule hf (n/160) as the shipped default; runners updated
Browse files- SHA256SUMS +4 -4
- frontend.py +1 -1
- manifest.json +1 -1
- phonon-coreml-src.tgz +2 -2
- phonon_coreml.py +15 -2
SHA256SUMS
CHANGED
|
@@ -2,12 +2,12 @@ ba3f19b2090b8b51919b153c4c47998a18d5581a7363334876aabd99ccc3a70e README.md
|
|
| 2 |
1c2debc9e81ff4cee6a1f0313a87784893c7095ed51e280122a0aa47c19e0519 NOTICE
|
| 3 |
9ba9550ad48438d0836ddab3da480b3b69ffa0aac7b7878b5a0039e7ab429411 LICENSE-WEIGHTS-CC-BY-4.0.txt
|
| 4 |
cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30 LICENSE-CODE-Apache-2.0.txt
|
| 5 |
-
|
| 6 |
fe289e3f061bdb71c628ddc6ce30edfe0b2c0915413423234bc3096457ecba1e decoder.bin
|
| 7 |
-
|
| 8 |
-
|
| 9 |
e56182a557f5bae30fe37bc8333cf9d0caf323aaae42b1e4465ad9270bf048f6 segmenter_np.py
|
| 10 |
-
|
| 11 |
695c112e2bbf6aa04b67e95a631e269d9643f7bb840f67313ab471cf7d8b242c ci/expected_texts.json
|
| 12 |
30885601173f96b0d8ddd020dc959b055c6c1582b85a33e3fcab8c4b08ed94c2 ci/clips/1089-134686-0000.flac
|
| 13 |
66277a3fa3df407261dc2a3ce685a7ceef19999ab0c10531bee5257cb64cb59d ci/clips/1089-134686-0002.flac
|
|
|
|
| 2 |
1c2debc9e81ff4cee6a1f0313a87784893c7095ed51e280122a0aa47c19e0519 NOTICE
|
| 3 |
9ba9550ad48438d0836ddab3da480b3b69ffa0aac7b7878b5a0039e7ab429411 LICENSE-WEIGHTS-CC-BY-4.0.txt
|
| 4 |
cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30 LICENSE-CODE-Apache-2.0.txt
|
| 5 |
+
8e2f8e012b86bd35cd77068dea84e27e2ae5bb35d18d613a4f540eee8742d77e manifest.json
|
| 6 |
fe289e3f061bdb71c628ddc6ce30edfe0b2c0915413423234bc3096457ecba1e decoder.bin
|
| 7 |
+
8194344c73512c9cc57cd2ecc9455218942705980e5c20a9401aa72cb112a10d phonon_coreml.py
|
| 8 |
+
a85dc4abab44b785333e338f22ac7bee2ac624425e0d2160e041b80022993bd7 frontend.py
|
| 9 |
e56182a557f5bae30fe37bc8333cf9d0caf323aaae42b1e4465ad9270bf048f6 segmenter_np.py
|
| 10 |
+
92cf20463e88908177efd01749d8e24a0cdf477979af637735b4bf5927abe560 phonon-coreml-src.tgz
|
| 11 |
695c112e2bbf6aa04b67e95a631e269d9643f7bb840f67313ab471cf7d8b242c ci/expected_texts.json
|
| 12 |
30885601173f96b0d8ddd020dc959b055c6c1582b85a33e3fcab8c4b08ed94c2 ci/clips/1089-134686-0000.flac
|
| 13 |
66277a3fa3df407261dc2a3ce685a7ceef19999ab0c10531bee5257cb64cb59d ci/clips/1089-134686-0002.flac
|
frontend.py
CHANGED
|
@@ -22,7 +22,7 @@ _WINDOW = np.hanning(WIN).astype(np.float32) # torch.hann_windo
|
|
| 22 |
_L = (N_FFT - WIN) // 2
|
| 23 |
_WIN512 = np.pad(_WINDOW, (_L, N_FFT - WIN - _L)) # torch.stft centres a short window inside n_fft
|
| 24 |
|
| 25 |
-
def log_mel(wave, rule="
|
| 26 |
"""wave float32 [n] 16 kHz -> feats float32 [128, T] normalised, T = n//160 (HF: features_lengths = n // hop; the STFT's
|
| 27 |
extra last frame is dropped, exactly as the HF attention mask drops it)."""
|
| 28 |
x = np.asarray(wave, dtype=np.float32); n = len(x)
|
|
|
|
| 22 |
_L = (N_FFT - WIN) // 2
|
| 23 |
_WIN512 = np.pad(_WINDOW, (_L, N_FFT - WIN - _L)) # torch.stft centres a short window inside n_fft
|
| 24 |
|
| 25 |
+
def log_mel(wave, rule="hf"):
|
| 26 |
"""wave float32 [n] 16 kHz -> feats float32 [128, T] normalised, T = n//160 (HF: features_lengths = n // hop; the STFT's
|
| 27 |
extra last frame is dropped, exactly as the HF attention mask drops it)."""
|
| 28 |
x = np.asarray(wave, dtype=np.float32); n = len(x)
|
manifest.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
| 10 |
35
|
| 11 |
],
|
| 12 |
"program_prefix": "enc_",
|
| 13 |
-
"frames_rule": "
|
| 14 |
"residual_scale": 64.0,
|
| 15 |
"weights": "int8 per output channel (the five-value encoder's one-dot values), 16-bit float activations; one weight blob shared by the four functions",
|
| 16 |
"inputs": "mel [1,128,T] fp32 normalised log-mel, zero-padded to the function's length; m1/m2/m3 frame masks after each stride-2 conv; kmask additive key mask over encoder tokens (0 / -1e4); pos [1,2*T3-1,1024] relative-position table",
|
|
|
|
| 10 |
35
|
| 11 |
],
|
| 12 |
"program_prefix": "enc_",
|
| 13 |
+
"frames_rule": "hf",
|
| 14 |
"residual_scale": 64.0,
|
| 15 |
"weights": "int8 per output channel (the five-value encoder's one-dot values), 16-bit float activations; one weight blob shared by the four functions",
|
| 16 |
"inputs": "mel [1,128,T] fp32 normalised log-mel, zero-padded to the function's length; m1/m2/m3 frame masks after each stride-2 conv; kmask additive key mask over encoder tokens (0 / -1e4); pos [1,2*T3-1,1024] relative-position table",
|
phonon-coreml-src.tgz
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:92cf20463e88908177efd01749d8e24a0cdf477979af637735b4bf5927abe560
|
| 3 |
+
size 21762
|
phonon_coreml.py
CHANGED
|
@@ -51,12 +51,25 @@ class Phonon2CoreML:
|
|
| 51 |
import coremltools as ct
|
| 52 |
self.m = json.load(open(os.path.join(bundle, "manifest.json"))); self.dec = DecoderBin(os.path.join(bundle, "decoder.bin"))
|
| 53 |
assert self.dec.container_sha256 == self.m["container_sha256"], "decoder.bin and manifest come from different containers"
|
| 54 |
-
self.frames = frames or self.m.get("frames_rule", "
|
| 55 |
for s in sorted(self.m["buckets_s"]):
|
| 56 |
fn = f"{self.m['program_prefix']}{int(s)}s"
|
| 57 |
-
if self.m.get("multifunction"):
|
|
|
|
|
|
|
|
|
|
| 58 |
else: self.progs[s] = ct.models.MLModel(os.path.join(bundle, fn + ".mlpackage"), compute_units=cu)
|
| 59 |
self.load_s = time.perf_counter() - t0; self.pos = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
@staticmethod
|
| 61 |
def frames_for(sec): return 1 + int(round(sec * 16000)) // HOP
|
| 62 |
@staticmethod
|
|
|
|
| 51 |
import coremltools as ct
|
| 52 |
self.m = json.load(open(os.path.join(bundle, "manifest.json"))); self.dec = DecoderBin(os.path.join(bundle, "decoder.bin"))
|
| 53 |
assert self.dec.container_sha256 == self.m["container_sha256"], "decoder.bin and manifest come from different containers"
|
| 54 |
+
self.frames = frames or self.m.get("frames_rule", "hf"); cu = getattr(ct.ComputeUnit, compute); self.progs = {}; t0 = time.perf_counter()
|
| 55 |
for s in sorted(self.m["buckets_s"]):
|
| 56 |
fn = f"{self.m['program_prefix']}{int(s)}s"
|
| 57 |
+
if self.m.get("multifunction"):
|
| 58 |
+
# compile once (coremltools compiles a .mlpackage on every load); keep the compiled copy beside the bundle or in ~/Library/Caches
|
| 59 |
+
pkg = os.path.join(bundle, self.m["multifunction"]); comp = self._compiled(pkg, cu)
|
| 60 |
+
self.progs[s] = ct.models.CompiledMLModel(comp, compute_units=cu, function_name=fn) if comp else ct.models.MLModel(pkg, function_name=fn, compute_units=cu)
|
| 61 |
else: self.progs[s] = ct.models.MLModel(os.path.join(bundle, fn + ".mlpackage"), compute_units=cu)
|
| 62 |
self.load_s = time.perf_counter() - t0; self.pos = {}
|
| 63 |
+
def _compiled(self, pkg, cu):
|
| 64 |
+
import coremltools as ct, shutil
|
| 65 |
+
name = os.path.splitext(os.path.basename(pkg))[0] + ".mlmodelc"
|
| 66 |
+
for d in (os.path.dirname(pkg), os.path.join(os.path.expanduser("~/Library/Caches/phonon-coreml"), self.m["container_sha256"][:16])):
|
| 67 |
+
c = os.path.join(d, name)
|
| 68 |
+
if os.path.isdir(c): return c
|
| 69 |
+
try:
|
| 70 |
+
tmp = ct.models.utils.compile_model(pkg); d = os.path.join(os.path.expanduser("~/Library/Caches/phonon-coreml"), self.m["container_sha256"][:16]); os.makedirs(d, exist_ok=True)
|
| 71 |
+
c = os.path.join(d, name); shutil.move(tmp, c); return c
|
| 72 |
+
except Exception: return None
|
| 73 |
@staticmethod
|
| 74 |
def frames_for(sec): return 1 + int(round(sec * 16000)) // HOP
|
| 75 |
@staticmethod
|