Enhance training script and evaluation logic to support all-future model target mode and improve error handling for distribution modes

This commit is contained in:
2026-06-12 11:53:35 +08:00
parent 82f70945d9
commit 1240766aa9
3 changed files with 20 additions and 8 deletions

View File

@@ -632,13 +632,15 @@ def compute_logits_for_disease_chunk(
device.type == "cuda" and use_amp) else torch.float32
weight = model.risk_head.weight[disease_ids].detach().to(
device=device, dtype=compute_dtype)
bias = model.risk_head.bias[disease_ids].detach().to(
device=device, dtype=compute_dtype)
parts: List[np.ndarray] = []
for start in tqdm(range(0, n, logit_batch_size), desc="Risk-head projection", leave=False, dynamic_ncols=True):
end = min(start + logit_batch_size, n)
h = torch.from_numpy(hidden_all[start:end]).to(
device=device, dtype=compute_dtype, non_blocking=True)
logits = torch.matmul(h, weight.t())
logits = torch.matmul(h, weight.t()) + bias
parts.append(logits.float().cpu().numpy().astype(
np.float32, copy=False))
del h, logits