Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

torch.fill_ can not apply after general function#1924

Open
fukatani wants to merge 2 commits intoapple:main from
fukatani:torch-pass
Open

torch.fill_ can not apply after general function #1924
fukatani wants to merge 2 commits intoapple:main from
fukatani:torch-pass

Conversation

@fukatani
Copy link
Contributor

@fukatani fukatani commented Jul 27, 2023

Resolves #1920

# update the mapping
node_output = node.outputs[0]
val = tensor_to_node_sequence_mapping[node_input]
tensor_to_node_sequence_mapping[node_output] = val
Copy link
Collaborator

@YifanShenSZ YifanShenSZ Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please share your reasoning on why this would be generally applicable for nodes in addition to to?

Also, what is the reason to delete line del tensor_to_node_sequence_mapping[node_input]? With that line, it makes tensor_to_node_sequence_mapping[node_output] to be ordered as latest

Copy link
Contributor Author

@fukatani fukatani Jul 29, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the reason to delete line del tensor_to_node_sequence_mapping[node_input]

with del tensor_to_node_sequence_mapping[node_input], if cast source is referenced more than once, ValueError will be raised.

class Net(torch.nn.Module):
 def forward(self, x):
 y = torch.empty(x.shape)
 z = y.to(torch.int32)
 w = y.to(torch.int32)
 return z, w

stacktrace

Traceback (most recent call last):
 File "/Users/ryosukefukatani/work/coremltools/onth11.py", line 21, in <module>
 ct.TensorType("x", shape=(ct.RangeDim(), ct.RangeDim())),
 File "/Users/ryosukefukatani/work/coremltools/coremltools/converters/_converters_entry.py", line 542, in convert
 main_pipeline=pass_pipeline,
 File "/Users/ryosukefukatani/work/coremltools/coremltools/converters/mil/converter.py", line 188, in mil_convert
 return _mil_convert(model, convert_from, convert_to, ConverterRegistry, MLModel, compute_units, **kwargs)
 File "/Users/ryosukefukatani/work/coremltools/coremltools/converters/mil/converter.py", line 217, in _mil_convert
 **kwargs
 File "/Users/ryosukefukatani/work/coremltools/coremltools/converters/mil/converter.py", line 286, in mil_convert_to_proto
 prog = frontend_converter(model, **kwargs)
 File "/Users/ryosukefukatani/work/coremltools/coremltools/converters/mil/converter.py", line 108, in __call__
 return load(*args, **kwargs)
 File "/Users/ryosukefukatani/work/coremltools/coremltools/converters/mil/frontend/torch/load.py", line 61, in load
 specification_version,
 File "/Users/ryosukefukatani/work/coremltools/coremltools/converters/mil/frontend/torch/converter.py", line 335, in __init__
 p(self.graph)
 File "/Users/ryosukefukatani/work/coremltools/coremltools/converters/mil/frontend/torch/torchir_passes.py", line 141, in generate_tensor_assignment_ops
 raise ValueError("No matching select or slice.")
ValueError: No matching select or slice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please share your reasoning on why this would be generally applicable for nodes in addition to to?

We need general solution of #1917

ex.

class Net(torch.nn.Module):
 def forward(self, x):
 y = torch.empty(x.shape) + 1
 y.fill_(0.0)
 return y
class Net(torch.nn.Module):
 def forward(self, x):
 y = torch.empty(x.shape) - 1
 y.fill_(0.0)
 return y
class Net(torch.nn.Module):
 def forward(self, x):
 y = torch.empty(x.shape) .flatten()
 y.fill_(0.0)
 return y

and all other operations.

)
y_cm = ct_model.predict({'x': x})['y']

assert((y_cm == np.zeros(shape)).all())
Copy link
Collaborator

@YifanShenSZ YifanShenSZ Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove the outmost parentheses to be assert all(y_cm == np.zeros(shape))?

jakesabathia2 reacted with thumbs up emoji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@YifanShenSZ YifanShenSZ YifanShenSZ left review comments

@jakesabathia2 jakesabathia2 Awaiting requested review from jakesabathia2

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

torch.fill_ can not apply after add function

AltStyle によって変換されたページ (->オリジナル) /