(model, cal_dataset, chunk_idx: str)
| 350 | |
| 351 | |
| 352 | def calibrate_model(model, cal_dataset, chunk_idx: str): |
| 353 | with torch.no_grad(): |
| 354 | for inp in tqdm(cal_dataset, desc="Calibrating Model: "): |
| 355 | # pass prompt and response |
| 356 | for batch in tqdm(inp[chunk_idx].keys(), desc="Batch: "): |
| 357 | if inp[chunk_idx][batch] is not None: |
| 358 | inputs_embeds = torch.tensor(inp[chunk_idx][batch]["hidden_state"]) |
| 359 | pos_emb = torch.tensor(inp[chunk_idx][batch]["pos_emb"]) |
| 360 | cache = torch.tensor(inp[chunk_idx][batch]["cache"]) |
| 361 | mask = inp[chunk_idx][batch]["mask"] |
| 362 | if isinstance(mask, dict): |
| 363 | global_mask = torch.tensor(mask["GLOBAL"]) |
| 364 | local_mask = torch.tensor(mask["SLIDING_LOCAL"]) |
| 365 | model( |
| 366 | inputs_embeds, |
| 367 | global_mask, |
| 368 | local_mask, |
| 369 | pos_emb, |
| 370 | *torch.split(cache, 1, dim=0), |
| 371 | ) |
| 372 | else: |
| 373 | mask = torch.tensor(mask) |
| 374 | model( |
| 375 | inputs_embeds, mask, pos_emb, *torch.split(cache, 1, dim=0) |
| 376 | ) |
| 377 | |
| 378 | |
| 379 | def export_to_et_ir( |
no test coverage detected