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(
140
140
std::vector<executorch::aten::StridesType> strides,
141
141
executorch::aten::ScalarType type,
142
142
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
+ }
143
153
return random_strided (
144
154
std::move (sizes),
145
155
std::move (strides),
146
156
type,
147
157
dynamism,
148
- std::uniform_real_distribution<float >(0 .0f , 1 . 0f ));
158
+ std::uniform_real_distribution<float >(0 .0f , upper_bound ));
149
159
}
150
160
151
161
TensorPtr randn_strided (
You can’t perform that action at this time.
0 commit comments