Skip to content

Use consistent integer types for n_rows and row IDs in random forest #8817

Open

Description

@chyunsu3

Currently, we use 32-bit int for the n_rows parameter of the random forest:

void fit(const raft::handle_t& user_handle,
RandomForestClassifierF* forest,
float* input,
int n_rows,
int n_cols,
int* labels,
int n_unique_labels,
RF_params rf_params,
rapids_logger::level_enum verbosity = rapids_logger::level_enum::info,
bool* bootstrap_masks = nullptr,
const double* sample_weight = nullptr,
bool input_row_major = false);

On the other hand, we use 64-bit integers to store row IDs in the internals of random forest implementation:

RowSampler(const raft::handle_t& handle,
const RF_params& rf_params,
std::int64_t n_rows,
std::int64_t n_sampled_rows,
int n_streams,
bool* bootstrap_masks,
const double* sample_weight)

rmm::device_uvector<std::int64_t>& sample(int tree_id, int stream_id, cudaStream_t stream)

template <typename DataT, typename LabelT, int TPB>
void launchNodeSplitKernel(const Dataset<DataT, LabelT>& dataset,
const NodeWorkItem* work_items,
Split<DataT>* splits,
const WorkloadInfo* workload_info,
size_t n_blocks_dimx,
size_t n_work_items,
std::int64_t* partition_row_ids,
cudaStream_t builder_stream);

inline void sample_features(std::int64_t* column_samples,
const NodeWorkItem* work_items,
size_t work_items_size,
std::int64_t treeid,
uint64_t seed,
std::int64_t sample_offset,
std::int64_t n,
std::int64_t k,
cudaStream_t stream)

auto partition_row_ids_bytes =
ML::checked_mul<std::size_t>(sizeof(std::int64_t), dataset.n_sampled_rows);

TODO: We need to decide whether to use 32-bit or 64-bit integer to store n_rows and row IDs and apply the consistent type everywhere.
If we were to choose 32-bit, we'd allocate smaller memory for row IDs in the builder kernel.

TODO: Add assertion in the Python-C++ boundary to ensure that the Python integer is representable as the integer type used in the C++ implementation.

Related: #2459, #4105

Activity

  1. added theissue type on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions