Mentions légales du service

Skip to content
Snippets Groups Projects
Verified Commit 4a4027aa authored by ANDREY Paul's avatar ANDREY Paul
Browse files

Fix possible issues with numpy 2 and future torch versions.

parent 3730011d
No related branches found
No related tags found
No related merge requests found
Pipeline #1100309 failed
......@@ -219,7 +219,7 @@ class MulticlassAccuracyPrecisionRecall(Metric[ClassifConfmat]):
"f-score": 2 * diag / (pred + true),
}
# Convert NaNs resulting from zero-division to zero.
scores = {k: np.nan_to_num(v, copy=False) for k, v in scores.items()}
scores = {k: np.nan_to_num(v) for k, v in scores.items()}
# Add a copy of the confusion matrix and return.
scores["confusion"] = confmat.copy()
return scores
......
......@@ -291,8 +291,8 @@ class BinaryRocAUC(Metric[AurocState]):
fneg = self._states.fneg[::-1]
# Compute true- and false-positive rates and derive AUC.
with np.errstate(invalid="ignore"):
tpr = np.nan_to_num(tpos / (tpos + fneg), copy=False)
fpr = np.nan_to_num(fpos / (fpos + tneg), copy=False)
tpr = np.nan_to_num(tpos / (tpos + fneg))
fpr = np.nan_to_num(fpos / (fpos + tneg))
auc = sklearn.metrics.auc(fpr, tpr)
return {
"tpr": tpr,
......
......@@ -445,7 +445,7 @@ class SklearnSGDModel(Model):
raise TypeError(
f"Invalid data type for 'SklearnSGDModel': '{type(array)}'."
)
return array.astype(self._dtype, copy=False) # type: ignore
return array.astype(self._dtype) # type: ignore
def _compute_sample_gradient(
self,
......
......@@ -167,9 +167,9 @@ class TorchModel(Model):
) -> Self:
"""Instantiate a TorchModel from a configuration dict."""
with io.BytesIO(bytes.fromhex(config["model"])) as buffer:
model = torch.load(buffer)
model = torch.load(buffer, weights_only=False)
with io.BytesIO(bytes.fromhex(config["loss"])) as buffer:
loss = torch.load(buffer)
loss = torch.load(buffer, weights_only=False)
if config.get("compile", False) and hasattr(torch, "compile"):
model = torch.compile(model)
return cls(model=model, loss=loss)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment