Instructions to use cowWhySo/AuroraASR-1M-MLX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use cowWhySo/AuroraASR-1M-MLX with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download cowWhySo/AuroraASR-1M-MLX --local-dir AuroraASR-1M-MLX
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
File size: 5,063 Bytes
a78c443 2d44270 a78c443 2d44270 a78c443 2d44270 a78c443 2d44270 a78c443 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | """Convert upstream AuroraASR FP32 PyTorch safetensors to native MLX layouts on CPU.
This program DOES NOT import MLX, and runs in standard Linux Google Colab.
All checkpoint tensor names are checked; unknown tensors cause conversion failure.
"""
import argparse,hashlib,json,shutil
from pathlib import Path
import numpy as np
from safetensors import safe_open
from safetensors.numpy import save_file
EXPECTED_SOURCE='cd307b54b4d666d6ad7dc982a7a58a96d6e7f942'
def digest(p):
h=hashlib.sha256()
with open(p,'rb') as f:
for chunk in iter(lambda:f.read(1024*1024),b''):h.update(chunk)
return h.hexdigest()
def tensor_data_digest(p):
# Hash of the tensor bytes only. The safetensors header serialises its metadata dict in
# arbitrary order, so the whole-file hash can differ between two identical conversions.
with open(p,'rb') as f:
n=int.from_bytes(f.read(8),'little'); f.seek(8+n)
return hashlib.sha256(f.read()).hexdigest()
def transform(name,w):
# torch [O,I/groups,K1,K2] -> MLX [O,K1,K2,I/groups]
if name in ('conv1.weight','conv_dw.weight','conv_pw.weight'):
assert w.ndim==4,(name,w.shape)
return np.ascontiguousarray(w.transpose(0,2,3,1))
# torch [O,I/groups,K] -> MLX [O,K,I/groups]
if name.endswith('.dw.weight'):
assert w.ndim==3,(name,w.shape)
return np.ascontiguousarray(w.transpose(0,2,1))
assert w.ndim in (1,2),(name,w.shape)
return np.ascontiguousarray(w)
def convert(source,dest):
source,dest=Path(source),Path(dest)
dest.mkdir(parents=True,exist_ok=True)
cfg=json.loads((source/'config.json').read_text())
if cfg.get('weight_quantization') is not None:
raise ValueError('Expected original FP32 checkpoint, not upstream int8/fp16 subfolder')
if int(cfg.get('num_unique_blocks',-1))!=4 or int(cfg.get('num_repeats',-1))!=2:
raise ValueError('Unexpected architecture; review source before conversion')
p=source/'model.safetensors'
assert p.is_file(), f'Upstream weight file missing: {p}'
weights={}
with safe_open(str(p),framework='np') as f:
keys=list(f.keys())
for k in keys:
a=f.get_tensor(k)
if a.dtype != np.float32:
raise ValueError(f'Non-FP32 weight {k}: {a.dtype}')
# Only known architecture tensor prefixes allowed.
if not (k.startswith(('blocks.','conv1.','conv_dw.','conv_pw.','stem_proj.','head.','final_ln.'))):
raise ValueError(f'Unknown source tensor: {k}')
weights[k]=transform(k,a)
count=sum(int(np.prod(v.shape)) for v in weights.values())
if count != 949073 or len(weights)!=132:
raise ValueError(f'Unexpected checkpoint key count or parameter count: {len(weights)}, {count}')
expected_convs={'conv1.weight':(16,3,3,1),'conv_dw.weight':(16,3,3,1),
'conv_pw.weight':(16,1,1,16)}
for i in range(4):expected_convs[f'blocks.{i}.dw.weight']=(128,15,1)
for name,shape in expected_convs.items():
if weights[name].shape!=shape:raise ValueError(f'{name}: {weights[name].shape} != {shape}')
for nm in ['bpe256.model','preprocessor_config.json']:
shutil.copy2(source/nm,dest/nm)
# The upstream config points auto_map at transformers code that is not shipped here, so a
# transformers AutoModel call would fail confusingly. Keep the dimensions, drop the pointers.
mlx_cfg={k:v for k,v in cfg.items() if k not in ('auto_map','transformers_version')}
mlx_cfg.update(architectures=['AuroraASRMLX'],model_type='aurora_asr_mlx')
(dest/'config.json').write_text(json.dumps(mlx_cfg,indent=2)+'\n')
out=dest/'model.safetensors'
save_file(weights,str(out),metadata={'format':'mlx','origin': 'AuroraAI-Research/AuroraASR-1M',
'reference_revision':EXPECTED_SOURCE,'weight_layout':'mlx-nhwc'})
# verify every tensor after roundtrip, not just total size
with safe_open(str(out),framework='np') as f:
assert set(f.keys())==set(weights)
for key in weights:
if not np.array_equal(f.get_tensor(key),weights[key]):raise AssertionError(key)
info={'format':'native-mlx-nn-fp32','source':'AuroraAI-Research/AuroraASR-1M',
'source_revision':EXPECTED_SOURCE,'source_checkpoint_sha256':digest(p),
'converted_sha256':digest(out),'tensor_data_sha256':tensor_data_digest(out),'tensor_count':len(weights),'parameter_count':count,
'config':mlx_cfg,'weights_file':'model.safetensors','architecture':'weight-shared conformer-lite CTC',
'conversion_checked':True,'mac_numerical_parity':'NOT_TESTED',
'native_mlx_benchmark':'NOT_TESTED'}
(dest/'native_manifest.json').write_text(json.dumps(info,indent=2)+'\n')
print(json.dumps({k:v for k,v in info.items() if k!='config'},indent=2))
return info
if __name__=='__main__':
ap=argparse.ArgumentParser();ap.add_argument('--source',required=True);ap.add_argument('--output',required=True)
args=ap.parse_args();convert(args.source,args.output)
|