Skip to content

Conversation

@nastaran78
Copy link
Collaborator

This PR introduces full support for custom RNG objects across the library. Previously, NePS relied on general/global RNG handling. With this update, users can now provide their own NumPy and PyTorch RNG instances for complete control over reproducibility.

Key Changes

  1. Support for custom RNGs instead of global RNGs
    The library no longer depends on global RNG state. Users who need strict reproducibility can now supply their own numpy_rng or torch_rng objects. If both are provided, NePS will use them directly and ignore the seed argument for NumPy and Torch.

  2. Custom Categorical distribution with RNG support
    PyTorch’s built-in Categorical distribution does not accept a Generator. To enable deterministic sampling, a custom wrapper class is added that forwards calls using the provided torch Generator.

  3. Handling for Bayesian optimization internals
    The BO backend is not thread-safe and temporarily modifies the global RNG because acquisition functions in PyTorch only work with the global generator. Since these APIs do not support custom RNGs, the modification is isolated and restored immediately.

Examples

Using an internal seed:

neps.run(..., seed=42)

Creates new custom NumPy and Torch RNGs based on the given seed.

Providing external RNGs:

neps.run(..., numpy_rng=my_np_rng, torch_rng=my_torch_rng)

NePS uses the user-supplied RNG objects directly. In this case, the seed argument is ignored for NumPy and Torch.

@nastaran78 nastaran78 changed the title add support of seeding feat: add support of seeding Nov 14, 2025
@Meganton
Copy link
Collaborator

Meganton commented Nov 14, 2025

maybe include a test for bo or some other full algorithm to see if it's deterministic given a seed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants