ValueGen Class — pytorch Architecture
Architecture documentation for the ValueGen class in vec_test_all_types.h from the pytorch codebase.
Entity Profile
Source Code
aten/src/ATen/test/vec_test_all_types.h lines 609–652
template <typename T>
struct ValueGen<T, true, false>
{
std::mt19937 gen;
std::normal_distribution<reduced_fp_to_float_t<T>> normal;
std::uniform_int_distribution<int> roundChance;
T _start;
T _stop;
bool use_sign_change = false;
bool use_round = true;
ValueGen() : ValueGen(std::numeric_limits<T>::min(), std::numeric_limits<T>::max())
{
}
ValueGen(uint64_t seed) : ValueGen(std::numeric_limits<T>::min(), std::numeric_limits<T>::max(), seed)
{
}
ValueGen(T start, T stop, uint64_t seed = TestSeed())
{
gen = std::mt19937(seed);
T mean = start * static_cast<T>(0.5) + stop * static_cast<T>(0.5);
//make it normal +-3sigma
T divRange = static_cast<T>(6.0);
T stdev = std::abs(stop / divRange - start / divRange);
normal = std::normal_distribution<reduced_fp_to_float_t<T>>{ mean, stdev };
// in real its hard to get rounded value
// so we will force it by uniform chance
roundChance = std::uniform_int_distribution<int>(0, 5);
_start = start;
_stop = stop;
}
T get()
{
T a = normal(gen);
//make rounded value ,too
auto rChoice = roundChance(gen);
if (rChoice == 1)
a = std::round(a);
if (a < _start)
return nextafter(_start, _stop);
if (a >= _stop)
return nextafter(_stop, _start);
return a;
}
};
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free