Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizer got an empty parameter list. #194

Open
lk1983823 opened this issue Jan 3, 2024 · 0 comments
Open

Optimizer got an empty parameter list. #194

lk1983823 opened this issue Jan 3, 2024 · 0 comments

Comments

@lk1983823
Copy link

lk1983823 commented Jan 3, 2024

I build a keras model and save it as onnx form.
I use tf2onnx to convert the model.

model_input_signature = [
    tf.TensorSpec(np.array((None, 3)), name='input'), 
]
output_path = "./save_for_mpc/" + model_name + ".onnx"
onnx_model, _ = tf2onnx.convert.from_keras(model,
    output_path=output_path,
    input_signature=model_input_signature
)

When I convert the onnx one to a torch model, it works successfully and can make inference.
However, when I set the model to a trainable one, it shows ValueError: optimizer got an empty parameter list.
Here is the code :

torch_model_1 = convert(onnx_model_path)

GraphModule(
(initializers): Module()
(sequential/mono_dense/MatMul): OnnxMatMul()
(sequential/mono_dense/PartitionedCall/split): OnnxSplit13()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/sub_1): OnnxBinaryMathOperation()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/PartitionedCall_1/Neg): OnnxNeg()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/PartitionedCall_1/Elu): ELU(alpha=1.0)
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/PartitionedCall_1/Neg_1): OnnxNeg()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/ones_like/Shape): OnnxShape()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/ones_like/Shape__7): OnnxCast()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/ones_like__8): OnnxCast()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/ones_like): OnnxExpand()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/mul): OnnxBinaryMathOperation()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/Elu): ELU(alpha=1.0)
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/add_1): OnnxBinaryMathOperation()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/add): OnnxBinaryMathOperation()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/Elu_1): ELU(alpha=1.0)
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/sub): OnnxBinaryMathOperation()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/LessEqual): OnnxCompare()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/SelectV2__9): OnnxCast()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/SelectV2__15): OnnxBinaryMathOperation()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/SelectV2__11): OnnxNot()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/SelectV2__13): OnnxCast()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/SelectV2__18): OnnxBinaryMathOperation()
(sequential/mono_dense/PartitionedCall/PartitionedCall_1/SelectV2): OnnxBinaryMathOperation()
(sequential/mono_dense/PartitionedCall/PartitionedCall/Neg): OnnxNeg()
(sequential/mono_dense/PartitionedCall/PartitionedCall/Elu): ELU(alpha=1.0)
(sequential/mono_dense/PartitionedCall/PartitionedCall/Neg_1): OnnxNeg()
(sequential/mono_dense/PartitionedCall/Elu): ELU(alpha=1.0)
(sequential/mono_dense/PartitionedCall/concat): OnnxConcat()
(sequential/mono_dense_1/MatMul): OnnxMatMul()
(sequential/mono_dense_1/PartitionedCall/split): OnnxSplit13()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/sub_1): OnnxBinaryMathOperation()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/PartitionedCall_1/Neg): OnnxNeg()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/PartitionedCall_1/Elu): ELU(alpha=1.0)
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/PartitionedCall_1/Neg_1): OnnxNeg()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/ones_like/Shape): OnnxShape()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/ones_like/Shape__22): OnnxCast()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/ones_like__23): OnnxCast()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/ones_like): OnnxExpand()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/mul): OnnxBinaryMathOperation()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/Elu): ELU(alpha=1.0)
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/add_1): OnnxBinaryMathOperation()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/add): OnnxBinaryMathOperation()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/Elu_1): ELU(alpha=1.0)
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/sub): OnnxBinaryMathOperation()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/LessEqual): OnnxCompare()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/SelectV2__26): OnnxNot()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/SelectV2__28): OnnxCast()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/SelectV2__33): OnnxBinaryMathOperation()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/SelectV2__24): OnnxCast()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/SelectV2__30): OnnxBinaryMathOperation()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall_1/SelectV2): OnnxBinaryMathOperation()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall/Neg): OnnxNeg()
(sequential/mono_dense_1/PartitionedCall/PartitionedCall/Elu): ELU(alpha=1.0)
(sequential/mono_dense_1/PartitionedCall/PartitionedCall/Neg_1): OnnxNeg()
(sequential/mono_dense_1/PartitionedCall/Elu): ELU(alpha=1.0)
(sequential/mono_dense_1/PartitionedCall/concat): OnnxConcat()
(sequential/mono_dense_2/MatMul): OnnxMatMul()
(sequential/mono_dense_2/PartitionedCall/split): OnnxSplit13()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/sub_1): OnnxBinaryMathOperation()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/PartitionedCall_1/Neg): OnnxNeg()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/PartitionedCall_1/Neg_1): OnnxNeg()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/ones_like/Shape): OnnxShape()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/ones_like/Shape__37): OnnxCast()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/ones_like__38): OnnxCast()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/ones_like): OnnxExpand()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/mul): OnnxBinaryMathOperation()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/add_1): OnnxBinaryMathOperation()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/add): OnnxBinaryMathOperation()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/sub): OnnxBinaryMathOperation()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/LessEqual): OnnxCompare()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/SelectV2__41): OnnxNot()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/SelectV2__43): OnnxCast()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/SelectV2__48): OnnxBinaryMathOperation()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/SelectV2__39): OnnxCast()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/SelectV2__45): OnnxBinaryMathOperation()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall_1/SelectV2): OnnxBinaryMathOperation()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall/Neg): OnnxNeg()
(sequential/mono_dense_2/PartitionedCall/PartitionedCall/Neg_1): OnnxNeg()
(sequential/mono_dense_2/PartitionedCall/concat): OnnxConcat()
)

loss_fn = torch.nn.MSELoss()
optimizer = torch.optim.Adam(torch_model_1.parameters())

this shows:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[/tmp/ipykernel_32945/3047762149.py](https://file+.vscode-resource.vscode-cdn.net/tmp/ipykernel_32945/3047762149.py) in 
      1 loss_fn = torch.nn.MSELoss()
----> 2 optimizer = torch.optim.Adam(torch_model_1.parameters())

[~/anaconda3/envs/dpc/lib/python3.10/site-packages/torch/optim/adam.py](https://file+.vscode-resource.vscode-cdn.net/media/lk/lksgcc/DL_lk/202205_RZ_GAN%E6%A8%A1%E5%9E%8B/model/EvoOpt/~/anaconda3/envs/dpc/lib/python3.10/site-packages/torch/optim/adam.py) in __init__(self, params, lr, betas, eps, weight_decay, amsgrad, foreach, maximize, capturable, differentiable, fused)
     31                         maximize=maximize, foreach=foreach, capturable=capturable,
     32                         differentiable=differentiable, fused=fused)
---> 33         super().__init__(params, defaults)
     34 
     35         if fused:

[~/anaconda3/envs/dpc/lib/python3.10/site-packages/torch/optim/optimizer.py](https://file+.vscode-resource.vscode-cdn.net/media/lk/lksgcc/DL_lk/202205_RZ_GAN%E6%A8%A1%E5%9E%8B/model/EvoOpt/~/anaconda3/envs/dpc/lib/python3.10/site-packages/torch/optim/optimizer.py) in __init__(self, params, defaults)
    185         param_groups = list(params)
    186         if len(param_groups) == 0:
--> 187             raise ValueError("optimizer got an empty parameter list")
    188         if not isinstance(param_groups[0], dict):
    189             param_groups = [{'params': param_groups}]

ValueError: optimizer got an empty parameter list

Python 3.10.0
onnx2torch 1.5.13
onnx 1.15.0
torch 2.0.1+cu117
tf2onnx 1.16.0
toymodel.zip
I have uploaded my onnx model. Can anyone give me some help? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant