From 595b9f41aa1cc11f3f4dbeca7b989c4b4367e0df Mon Sep 17 00:00:00 2001 From: gs-olive <113141689+gs-olive@users.noreply.github.com> Date: Fri, 28 Oct 2022 00:24:12 -0700 Subject: [PATCH] fix: Resolve cuda 710 error when compiling BERT models - Issue arising when compiling BERT models with 3+ inputs - Added temporary fix by decreasing the range of allowed values to the random number generator for creating input tensors to [0,2), instead of [0,5) - Used random float inputs in the range [0, 2) instead of int, then casted to desired type. The ultimate effect of this change with regard to bug #1418, is random floats are selected in the range [0, 2), then casted to Int, effectively making the range of allowed ints {0, 1}, as required by the model - More robust fix to follow --- core/partitioning/shape_analysis.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/partitioning/shape_analysis.cpp b/core/partitioning/shape_analysis.cpp index b49a0efc72..45cd678bd5 100644 --- a/core/partitioning/shape_analysis.cpp +++ b/core/partitioning/shape_analysis.cpp @@ -12,16 +12,24 @@ namespace partitioning { at::Tensor generateSingleInput(ir::Input& input, c10::optional& type_opt) { auto cur_shape = input.input_shape; std::vector shape; + + // Initialize min and max ranges for random number selection + int LoValIncl = 0; + int HiValExcl = 2; + shape.insert(shape.begin(), std::begin(cur_shape.d), std::begin(cur_shape.d) + cur_shape.nbDims); - // auto type_opt = types[input.first][i]; + auto type = at::kFloat; if (type_opt) { type = type_opt.value(); } else { LOG_WARNING("Input type for doing shape analysis could not be determined, defaulting to F32"); } - auto in = at::randint(5, shape, {at::kCUDA}).to(type); - // ivalue_map[input.first] = in.clone(); + + // Make the value range for input tensor a uniform (float) distribution + // over [LoValIncl, HiValExcl), then cast to the desired dtype + auto in = ((HiValExcl - LoValIncl) * at::rand(shape, {at::kCUDA}) + LoValIncl).to(type); + return in; }