Fix implicit cast in custom_function (#46445)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/46445
Fix an instance in which a truncated integer prevents downstream type safety checks.
Test Plan: I'm not sure what's appropriate here.
Reviewed By: albanD
Differential Revision: D24339292
fbshipit-source-id: 15748ec64446344ff1a8344005385906d3484d7c
diff --git a/torch/csrc/autograd/custom_function.h b/torch/csrc/autograd/custom_function.h
index 9aefb55..055fefd 100644
--- a/torch/csrc/autograd/custom_function.h
+++ b/torch/csrc/autograd/custom_function.h
@@ -273,12 +273,12 @@
auto outputs = T::backward(&ctx_, backward_inputs);
int num_forward_inputs = is_variable_input_.size();
- int num_outputs = outputs.size();
+ auto num_outputs = outputs.size();
// Returning too many results is ok, but only as long as they're all undefined.
// Truncate the result vector in that case.
if (num_outputs > num_forward_inputs) {
bool all_undef = true;
- for (int i = num_forward_inputs; i < num_outputs; ++i) {
+ for (size_t i = num_forward_inputs; i < num_outputs; ++i) {
all_undef &= (!outputs[i].defined());
}
if (all_undef) {