MCPcopy Create free account
hub / github.com/pytorch/executorch / calibrate_model

Function calibrate_model

examples/mediatek/model_export_scripts/whisper.py:376–393  ·  view source on GitHub ↗
(model, cal_dataset, chunk_idx: str)

Source from the content-addressed store, hash-verified

374
375
376def calibrate_model(model, cal_dataset, chunk_idx: str):
377 with torch.no_grad():
378 for inp in tqdm(cal_dataset, desc="Calibrating Model: "):
379 # pass prompt and response
380 for batch in tqdm(inp[chunk_idx].keys(), desc="Batch: "):
381 if inp[chunk_idx][batch] is not None:
382 inputs_embeds = torch.tensor(inp[chunk_idx][batch]["hidden_state"])
383 mask = torch.tensor(inp[chunk_idx][batch]["mask"])
384 pos_emb = torch.tensor(inp[chunk_idx][batch]["pos_emb"])
385 cache = torch.tensor(inp[chunk_idx][batch]["cache"])
386 cross_cache = torch.tensor(inp[chunk_idx][batch]["cross_cache"])
387 model(
388 inputs_embeds,
389 mask,
390 pos_emb,
391 cross_cache,
392 *torch.split(cache, 1, dim=0),
393 )
394
395
396def export_to_et_ir(

Callers 1

export_to_et_irFunction · 0.70

Calls 2

keysMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected