Skip to content

Commit 6829cba

Browse files
committed
ensure source and external_data.source have distinct file names
1 parent a411512 commit 6829cba

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/bioimageio/spec/model/v0_5.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
FileSource,
6767
WithSuffix,
6868
YamlValue,
69+
extract_file_name,
6970
get_reader,
7071
wo_special_file_name,
7172
)
@@ -2376,6 +2377,19 @@ class OnnxWeightsDescr(WeightsEntryDescrBase):
23762377
"""Source of the external ONNX data file holding the weights.
23772378
(If present **source** holds the ONNX architecture without weights)."""
23782379

2380+
@model_validator(mode="after")
2381+
def _validate_external_data_unique_file_name(self) -> Self:
2382+
if self.external_data is not None and (
2383+
extract_file_name(self.source)
2384+
== extract_file_name(self.external_data.source)
2385+
):
2386+
raise ValueError(
2387+
f"ONNX `external_data` file name '{extract_file_name(self.external_data.source)}'"
2388+
+ " must be different from ONNX `source` file name."
2389+
)
2390+
2391+
return self
2392+
23792393

23802394
class PytorchStateDictWeightsDescr(WeightsEntryDescrBase):
23812395
type = "pytorch_state_dict"

0 commit comments

Comments
 (0)