MCPcopy Create free account
hub / github.com/modelscope/FunASR / main

Function main

runtime/llama.cpp/export_vad_gguf.py:11–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9 v=[x for x in b if x.size>1]; return v[0], v[1] # shift, scale (both 400-dim)
10
11def main():
12 ap=argparse.ArgumentParser()
13 ap.add_argument("--model_pt",required=True); ap.add_argument("--mvn",required=True); ap.add_argument("--out",required=True)
14 a=ap.parse_args()
15 sd=torch.load(a.model_pt,map_location="cpu"); sd=sd.get("state_dict",sd)
16 w=gguf.GGUFWriter(a.out,"fsmn-vad")
17 w.add_uint32("vad.input_dim",400); w.add_uint32("vad.input_affine_dim",140)
18 w.add_uint32("vad.linear_dim",250); w.add_uint32("vad.proj_dim",128)
19 w.add_uint32("vad.fsmn_layers",4); w.add_uint32("vad.lorder",20)
20 w.add_uint32("vad.output_affine_dim",140); w.add_uint32("vad.output_dim",248)
21 w.add_uint32("vad.n_mels",80); w.add_uint32("vad.lfr_m",5); w.add_uint32("vad.lfr_n",1)
22 shift,scale=parse_mvn(a.mvn); w.add_tensor("cmvn.shift",shift); w.add_tensor("cmvn.scale",scale)
23 n=0
24 for k,v in sd.items():
25 if not k.startswith("encoder."): continue
26 arr=v.detach().to(torch.float32).contiguous().numpy()
27 if k.endswith("conv_left.weight"): # (C,1,lorder,1) -> (lorder,C) tap-major
28 arr=np.ascontiguousarray(arr[:,0,:,0].T)
29 w.add_tensor(k,arr); n+=1
30 print(f"writing {n} tensors (+cmvn) to {a.out}")
31 w.write_header_to_file(); w.write_kv_data_to_file(); w.write_tensors_to_file(); w.close()
32 print(f"done: {a.out} ({os.path.getsize(a.out)/1e6:.1f} MB)")
33
34if __name__=="__main__": main()

Callers 1

export_vad_gguf.pyFile · 0.70

Calls 2

parse_mvnFunction · 0.70
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…