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

Function calibrate_model

examples/mediatek/model_export_scripts/llama.py:311–321  ·  view source on GitHub ↗
(model, cal_dataset, chunk_idx: str)

Source from the content-addressed store, hash-verified

309
310
311def calibrate_model(model, cal_dataset, chunk_idx: str):
312 with torch.no_grad():
313 for inp in tqdm(cal_dataset, desc="Calibrating Model: "):
314 # pass prompt and response
315 for batch in tqdm(inp[chunk_idx].keys(), desc="Batch: "):
316 if inp[chunk_idx][batch] is not None:
317 inputs_embeds = torch.tensor(inp[chunk_idx][batch]["hidden_state"])
318 mask = torch.tensor(inp[chunk_idx][batch]["mask"])
319 pos_emb = torch.tensor(inp[chunk_idx][batch]["pos_emb"])
320 cache = torch.tensor(inp[chunk_idx][batch]["cache"])
321 model(inputs_embeds, mask, pos_emb, *torch.split(cache, 1, dim=0))
322
323
324def 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