mirror of
https://github.com/wassname/pytorch-ts.git
synced 2026-08-11 11:24:31 +08:00
fix for pytorch 1.5 and pydantic
This commit is contained in:
+6
-12
@@ -95,26 +95,22 @@ def validated(base_model=None):
|
||||
param.annotation
|
||||
if param.annotation != inspect.Parameter.empty
|
||||
else Any,
|
||||
param.default
|
||||
if param.default != inspect.Parameter.empty
|
||||
else ...,
|
||||
param.default if param.default != inspect.Parameter.empty else ...,
|
||||
)
|
||||
for param in init_params.values()
|
||||
if param.name != "self"
|
||||
and param.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD
|
||||
and param.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD
|
||||
}
|
||||
|
||||
if base_model is None:
|
||||
PydanticModel = create_model(
|
||||
model_name=f"{init_clsnme}Model",
|
||||
f"{init_clsnme}Model",
|
||||
__config__=BaseValidatedInitializerModel.Config,
|
||||
**init_fields,
|
||||
)
|
||||
else:
|
||||
PydanticModel = create_model(
|
||||
model_name=f"{init_clsnme}Model",
|
||||
__base__=base_model,
|
||||
**init_fields,
|
||||
f"{init_clsnme}Model", __base__=base_model, **init_fields,
|
||||
)
|
||||
|
||||
def validated_repr(self) -> str:
|
||||
@@ -129,9 +125,7 @@ def validated(base_model=None):
|
||||
|
||||
nmargs = {
|
||||
name: arg
|
||||
for (name, param), arg in zip(
|
||||
list(init_params.items()), [self] + args
|
||||
)
|
||||
for (name, param), arg in zip(list(init_params.items()), [self] + args)
|
||||
if name != "self"
|
||||
}
|
||||
model = PydanticModel(**{**nmargs, **kwargs})
|
||||
@@ -160,4 +154,4 @@ def validated(base_model=None):
|
||||
|
||||
return init_wrapper
|
||||
|
||||
return validator
|
||||
return validator
|
||||
|
||||
@@ -230,9 +230,9 @@ def test_lowrank_multivariate_normal() -> None:
|
||||
Sigma = cov_factor @ cov_factor.T + cov_diag
|
||||
|
||||
distr = LowRankMultivariateNormal(
|
||||
loc=torch.Tensor(loc),
|
||||
cov_diag=torch.Tensor(np.diag(cov_diag)),
|
||||
cov_factor=torch.Tensor(cov_factor),
|
||||
loc=torch.Tensor(loc.copy()),
|
||||
cov_diag=torch.Tensor(np.diag(cov_diag).copy()),
|
||||
cov_factor=torch.Tensor(cov_factor.copy()),
|
||||
)
|
||||
|
||||
assert np.allclose(
|
||||
|
||||
Reference in New Issue
Block a user