-
Notifications
You must be signed in to change notification settings - Fork 364
fix: converter renaming already named tensors #1167
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
Changes from 1 commit
a901b0c
c169a81
cb5c06b
8b66d3d
74d4df1
248d8aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,8 +130,11 @@ ConversionCtx::~ConversionCtx() { | |
} | ||
|
||
nvinfer1::ITensor* ConversionCtx::AssociateValueAndTensor(const torch::jit::Value* value, nvinfer1::ITensor* tensor) { | ||
if (!AddNamedTensor(value, tensor)) { | ||
LOG_WARNING( | ||
"Trying to rewrite the name " << value->debugName() << " to a named ITensor " << tensor->getName() << "."); | ||
} | ||
tensor->setName(value->debugName().c_str()); | ||
this->value_tensor_map[value] = tensor; | ||
return tensor; | ||
} | ||
|
||
|
@@ -140,6 +143,12 @@ torch::jit::IValue* ConversionCtx::AssociateValueAndIValue(const torch::jit::Val | |
return &this->evaluated_value_map[value]; | ||
} | ||
|
||
bool ConversionCtx::AddNamedTensor(const torch::jit::Value* value, nvinfer1::ITensor* tensor) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should call this something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about just RecordITensor() ?. It will record or else warn if the ITensor is new. |
||
value_tensor_map[value] = tensor; | ||
auto ret = named_tensors.insert(tensor); | ||
return ret.second; | ||
} | ||
|
||
std::string ConversionCtx::SerializeEngine() { | ||
#if NV_TENSORRT_MAJOR > 7 | ||
auto serialized_network = builder->buildSerializedNetwork(*net, *cfg); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ struct ConversionCtx { | |
ConversionCtx(BuilderSettings settings); | ||
std::string SerializeEngine(); | ||
nvinfer1::ITensor* AssociateValueAndTensor(const torch::jit::Value* value, nvinfer1::ITensor* tensor); | ||
bool AddNamedTensor(const torch::jit::Value* value, nvinfer1::ITensor* tensor); | ||
torch::jit::IValue* AssociateValueAndIValue(const torch::jit::Value* value, torch::jit::IValue tensor); | ||
bool CheckLayerAddition(const torch::jit::Node* n); | ||
|
||
|
@@ -69,6 +70,9 @@ struct ConversionCtx { | |
|
||
std::unordered_map<const torch::jit::Value*, nvinfer1::ITensor*> value_tensor_map; | ||
std::unordered_map<const torch::jit::Value*, torch::jit::IValue> evaluated_value_map; | ||
|
||
// record already named ITensors to prevent rewriting another name to the same tensor | ||
std::unordered_set<nvinfer1::ITensor*> named_tensors; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we call this |
||
}; | ||
|
||
} // namespace conversion | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should put the warning in
AddNamedTensor
so there is no way to get around the warning.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with this. We should warn inside the RecordNewTensor so that it will be generic if we use this call elsewhere.