Refactor bias handling in AUC evaluation scripts to improve robustness and prevent errors when bias is not defined
This commit is contained in:
@@ -632,6 +632,8 @@ def compute_logits_for_disease_chunk(
|
|||||||
device.type == "cuda" and use_amp) else torch.float32
|
device.type == "cuda" and use_amp) else torch.float32
|
||||||
weight = model.risk_head.weight[disease_ids].detach().to(
|
weight = model.risk_head.weight[disease_ids].detach().to(
|
||||||
device=device, dtype=compute_dtype)
|
device=device, dtype=compute_dtype)
|
||||||
|
bias = None
|
||||||
|
if model.risk_head.bias is not None:
|
||||||
bias = model.risk_head.bias[disease_ids].detach().to(
|
bias = model.risk_head.bias[disease_ids].detach().to(
|
||||||
device=device, dtype=compute_dtype)
|
device=device, dtype=compute_dtype)
|
||||||
|
|
||||||
@@ -640,7 +642,9 @@ def compute_logits_for_disease_chunk(
|
|||||||
end = min(start + logit_batch_size, n)
|
end = min(start + logit_batch_size, n)
|
||||||
h = torch.from_numpy(hidden_all[start:end]).to(
|
h = torch.from_numpy(hidden_all[start:end]).to(
|
||||||
device=device, dtype=compute_dtype, non_blocking=True)
|
device=device, dtype=compute_dtype, non_blocking=True)
|
||||||
logits = torch.matmul(h, weight.t()) + bias
|
logits = torch.matmul(h, weight.t())
|
||||||
|
if bias is not None:
|
||||||
|
logits = logits + bias
|
||||||
parts.append(logits.float().cpu().numpy().astype(
|
parts.append(logits.float().cpu().numpy().astype(
|
||||||
np.float32, copy=False))
|
np.float32, copy=False))
|
||||||
del h, logits
|
del h, logits
|
||||||
|
|||||||
@@ -839,6 +839,8 @@ def project_distribution_chunk(
|
|||||||
device.type == "cuda" and use_amp) else torch.float32
|
device.type == "cuda" and use_amp) else torch.float32
|
||||||
weight = model.risk_head.weight[disease_ids].detach().to(
|
weight = model.risk_head.weight[disease_ids].detach().to(
|
||||||
device=device, dtype=compute_dtype)
|
device=device, dtype=compute_dtype)
|
||||||
|
bias = None
|
||||||
|
if model.risk_head.bias is not None:
|
||||||
bias = model.risk_head.bias[disease_ids].detach().to(
|
bias = model.risk_head.bias[disease_ids].detach().to(
|
||||||
device=device, dtype=compute_dtype)
|
device=device, dtype=compute_dtype)
|
||||||
rho_weight = None
|
rho_weight = None
|
||||||
@@ -868,7 +870,9 @@ def project_distribution_chunk(
|
|||||||
end = min(start + logit_batch_size, n)
|
end = min(start + logit_batch_size, n)
|
||||||
h = torch.from_numpy(hidden_all[start:end]).to(
|
h = torch.from_numpy(hidden_all[start:end]).to(
|
||||||
device=device, dtype=compute_dtype, non_blocking=True)
|
device=device, dtype=compute_dtype, non_blocking=True)
|
||||||
logits = torch.matmul(h, weight.t()) + bias
|
logits = torch.matmul(h, weight.t())
|
||||||
|
if bias is not None:
|
||||||
|
logits = logits + bias
|
||||||
rho = None
|
rho = None
|
||||||
if dist_mode == "weibull":
|
if dist_mode == "weibull":
|
||||||
assert rho_weight is not None and rho_bias is not None
|
assert rho_weight is not None and rho_bias is not None
|
||||||
|
|||||||
Reference in New Issue
Block a user