@@ -318,10 +318,7 @@ void mnmg_fit(const raft::resources& handle,
318318 true );
319319 }
320320
321- bool need_compute_norms = metric == cuvs::distance::DistanceType::L2Expanded ||
322- metric == cuvs::distance::DistanceType::L2SqrtExpanded;
323- auto h_norm_cache =
324- raft::make_pinned_vector<T, IdxT>(dev_res, (need_compute_norms && has_data) ? n_local : 0 );
321+ auto h_norm_cache = raft::make_pinned_vector<T, IdxT>(dev_res, has_data ? n_local : 0 );
325322 bool norms_cached = false ;
326323
327324 auto mnmg_allreduce = [&](auto * sendbuf, auto * recvbuf, size_t count) {
@@ -407,21 +404,19 @@ void mnmg_fit(const raft::resources& handle,
407404 auto L2NormBatch_view =
408405 raft::make_device_vector_view<T, IdxT>(L2NormBatch.data_handle (), current_batch_size);
409406
410- if (need_compute_norms) {
411- auto batch_offset = static_cast <IdxT>(data_batch.offset ());
412- if (!norms_cached) {
413- raft::linalg::norm<raft::linalg::L2Norm, raft::Apply::ALONG_ROWS >(
414- dev_res, batch_data_view, L2NormBatch_view);
415- raft::copy (h_norm_cache.data_handle () + batch_offset,
416- L2NormBatch.data_handle (),
417- current_batch_size,
418- stream);
419- } else {
420- raft::copy (L2NormBatch.data_handle (),
421- h_norm_cache.data_handle () + batch_offset,
422- current_batch_size,
423- stream);
424- }
407+ auto batch_offset = static_cast <IdxT>(data_batch.offset ());
408+ if (!norms_cached) {
409+ raft::linalg::norm<raft::linalg::L2Norm, raft::Apply::ALONG_ROWS >(
410+ dev_res, batch_data_view, L2NormBatch_view);
411+ raft::copy (h_norm_cache.data_handle () + batch_offset,
412+ L2NormBatch.data_handle (),
413+ current_batch_size,
414+ stream);
415+ } else {
416+ raft::copy (L2NormBatch.data_handle (),
417+ h_norm_cache.data_handle () + batch_offset,
418+ current_batch_size,
419+ stream);
425420 }
426421
427422 auto L2NormBatch_const = raft::make_const_mdspan (L2NormBatch_view);
@@ -447,7 +442,7 @@ void mnmg_fit(const raft::resources& handle,
447442 raft::make_device_scalar_view (clustering_cost.data_handle ()),
448443 batch_workspace);
449444 }
450- if (need_compute_norms) { norms_cached = true ; }
445+ norms_cached = true ;
451446 }
452447
453448 // Phase 2: grouped allreduce
0 commit comments