File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -188,7 +188,7 @@ void AddInputs(
188
188
ctx->input_is_dynamic = true ;
189
189
}
190
190
191
- ctx->value_tensor_map [in] = trt_in;
191
+ ctx->RecordNewITensor (in, trt_in) ;
192
192
ctx->num_inputs += 1 ;
193
193
}
194
194
Original file line number Diff line number Diff line change @@ -143,8 +143,8 @@ ConversionCtx::~ConversionCtx() {
143
143
}
144
144
145
145
nvinfer1::ITensor* ConversionCtx::AssociateValueAndTensor (const torch::jit::Value* value, nvinfer1::ITensor* tensor) {
146
- tensor-> setName (value-> debugName (). c_str () );
147
- this -> value_tensor_map [value] = tensor;
146
+ RecordNewITensor (value, tensor );
147
+
148
148
return tensor;
149
149
}
150
150
@@ -153,6 +153,15 @@ torch::jit::IValue* ConversionCtx::AssociateValueAndIValue(const torch::jit::Val
153
153
return &this ->evaluated_value_map [value];
154
154
}
155
155
156
+ void ConversionCtx::RecordNewITensor (const torch::jit::Value* value, nvinfer1::ITensor* tensor) {
157
+ value_tensor_map[value] = tensor;
158
+ auto ret = seen_itensors.insert (tensor);
159
+ if (!ret.second ) {
160
+ LOG_WARNING (
161
+ " Trying to record the value " << value->debugName () << " with the ITensor " << tensor->getName () << " again." );
162
+ }
163
+ }
164
+
156
165
std::string ConversionCtx::SerializeEngine () {
157
166
#if NV_TENSORRT_MAJOR > 7
158
167
auto serialized_network = builder->buildSerializedNetwork (*net, *cfg);
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ struct ConversionCtx {
48
48
ConversionCtx (BuilderSettings settings);
49
49
std::string SerializeEngine ();
50
50
nvinfer1::ITensor* AssociateValueAndTensor (const torch::jit::Value* value, nvinfer1::ITensor* tensor);
51
+ void RecordNewITensor (const torch::jit::Value* value, nvinfer1::ITensor* tensor);
51
52
torch::jit::IValue* AssociateValueAndIValue (const torch::jit::Value* value, torch::jit::IValue tensor);
52
53
bool CheckLayerAddition (const torch::jit::Node* n);
53
54
@@ -71,6 +72,9 @@ struct ConversionCtx {
71
72
72
73
std::unordered_map<const torch::jit::Value*, nvinfer1::ITensor*> value_tensor_map;
73
74
std::unordered_map<const torch::jit::Value*, torch::jit::IValue> evaluated_value_map;
75
+
76
+ // record already named ITensors to prevent rewriting another name to the same tensor
77
+ std::unordered_set<nvinfer1::ITensor*> seen_itensors;
74
78
};
75
79
76
80
} // namespace conversion
You can’t perform that action at this time.
0 commit comments