Skip to content

Conversation

ruoqianguo
Copy link
Contributor

Signed-off-by: Ruoqian Guo ruoqiang@nvidia.com

Description

Fix Split Converter bugs.

  1. Fix bug in core/conversion/converters/select.cpp: add_split function.
  2. Modified the Var::ITensorOrFreeze function in core/conversion/var/Var.cpp.

In addition, i use the linters to ensure that my code matches the style guidelines. The linters changed the entire file(core/conversion/converters/impl/select.cpp) . I only modified the add_split part in select.cpp.

Fixes #401

Type of change

Please delete options that are not relevant and/or add your own.

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes

}
if (numRemainder) {
numOutputs += 1;
sizes.push_back(numRemainder);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only modified the add_split function in select.cpp.

Signed-off-by: Ruoqian Guo <ruoqiang@nvidia.com>
@narendasan
Copy link
Collaborator

Is this really a breaking change?

@@ -27,10 +27,13 @@ bool add_split(ConversionCtx* ctx, const torch::jit::Node* n, args& args, bool s
} else {
auto split_size = args[1].unwrapToInt();
numOutputs = inDimSize / split_size;
if (numOutputs == 1) {
numRemainder = inDimSize % split_size;
for (int i = 0; i < numOutputs; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

style thing: use int64_t if possible

const_layer->setName(("[Freeze Tensor " + tensor_id.str() + " ]").c_str());
if (ptr_.ivalue->isTensor()) {
auto tensor = ptr_.ivalue->toTensor();
if (tensor.scalar_type() == at::kLong) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove this? #407 is adding a formal API to support this.

Comment on lines +120 to +122
// Split converter generates c10::IValue which hold TensorContainer.
auto output_container = ptr_.ivalue->toCustomClass<TensorContainer>();
out = output_container.get()->tensor();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks good to me.
Previously for split, we only considered cases with split as the final output or the list unpack as the final output, which is why the bug occurred for ops that followed them.

…Var.cpp

Signed-off-by: Ruoqian Guo <ruoqiang@nvidia.com>
Copy link
Collaborator

@narendasan narendasan left a comment

Choose a reason for hiding this comment

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

lgtm

@narendasan narendasan merged commit c0b9ec0 into pytorch:master Mar 22, 2021
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

Successfully merging this pull request may close these issues.

🐛 [Bug] Split converter bugs
3 participants