File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -140,12 +140,22 @@ TensorPtr rand_strided(
140140 std::vector<executorch::aten::StridesType> strides,
141141 executorch::aten::ScalarType type,
142142 executorch::aten::TensorShapeDynamism dynamism) {
143+ auto upper_bound = 1 .0f ;
144+ // Adjusts the upper bound to prevent rounding to 1.0 when converting to
145+ // lower-precision types.
146+ if (type == executorch::aten::ScalarType::Half) {
147+ upper_bound -=
148+ float (std::numeric_limits<executorch::aten::Half>::epsilon ()) / 2 ;
149+ } else if (type == executorch::aten::ScalarType::BFloat16) {
150+ upper_bound -=
151+ float (std::numeric_limits<executorch::aten::BFloat16>::epsilon ()) / 2 ;
152+ }
143153 return random_strided (
144154 std::move (sizes),
145155 std::move (strides),
146156 type,
147157 dynamism,
148- std::uniform_real_distribution<float >(0 .0f , 1 . 0f ));
158+ std::uniform_real_distribution<float >(0 .0f , upper_bound ));
149159}
150160
151161TensorPtr randn_strided (
You can’t perform that action at this time.
0 commit comments