Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nans in naive kl divergence kernel introduced by div by 0. #724

Merged
merged 2 commits into from
Jun 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions cpp/test/distance/distance_base.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,13 @@ __global__ void naiveKLDivergenceDistanceKernel(
if (midx >= m || nidx >= n) return;
OutType acc = OutType(0);
for (int i = 0; i < k; ++i) {
int xidx = isRowMajor ? i + midx * k : i * m + midx;
int yidx = isRowMajor ? i + nidx * k : i * n + nidx;
auto a = x[xidx];
auto b = y[yidx];
bool b_zero = (b == 0);
const auto m = (!b_zero) * (a / b);
const bool m_zero = (m == 0);
acc += (a * (!m_zero) * log(m + m_zero));
int xidx = isRowMajor ? i + midx * k : i * m + midx;
int yidx = isRowMajor ? i + nidx * k : i * n + nidx;
auto a = x[xidx];
auto b = y[yidx];
bool b_zero = (b == 0);
bool a_zero = (a == 0);
acc += a * (log(a + a_zero) - log(b + b_zero));
}
acc = 0.5f * acc;
int outidx = isRowMajor ? midx * n + nidx : midx + m * nidx;
Expand Down Expand Up @@ -450,10 +449,6 @@ class DistanceTest : public ::testing::TestWithParam<DistanceInputs<DataType>> {
}
naiveDistance(
dist_ref.data(), x.data(), y.data(), m, n, k, distanceType, isRowMajor, metric_arg, stream);
// size_t worksize = raft::distance::getWorkspaceSize<distanceType, DataType, DataType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is unneeded, can it just be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is commented code which I've already removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! Wow, I totally misread the diff.

// DataType>(
// x.data(), y.data(), m, n, k);
// rmm::device_uvector<char> workspace(worksize, stream);

DataType threshold = -10000.f;

Expand Down