Skip to content

Document RAPIDS on Modal notebooks #613

Open

Description

@ncclementi

Notice that Modal notebooks defaul has a pre-defined enviornment.

Look into how to get cudf and cuml included in here: https://github.com/modal-labs/modal-client/blob/v1.1.3/modal/experimental/__init__.py#L234-L342

Activity

  1. ncclementi commented on Jan 16, 2026

    @ncclementi
    ContributorAuthor

    I've been trying to get this to work, but I'm running into several issues.

    The first approach I triad was to install cudf via uv directly in the notebook as suggested in the docs.

    But when I try to use it and run some simple code, it fails, as it's not finding the GPUs, like it's not visible. Even though nvidia-smi shows the GPU

    Steps to reproduce:

    • Enable a GPU in the notebook
    • %uv pip install "cudf-cu13==25.12.*"
    import cudf 
    
    s = cudf.Series([1, 2, 3])
    s.apply(lambda x: x+1)
    ---------------------------------------------------------------------------
    IndexError                                Traceback (most recent call last)
    File /usr/local/lib/python3.12/site-packages/cudf/core/indexed_frame.py:3572, in IndexedFrame._apply(self, func, kernel_class, *args, **kwargs)
       3571     kr = kernel_class(self, func, args)
    -> 3572     kernel, retty = kr.get_kernel()
       3573 except Exception as e:
    
    File /usr/local/lib/python3.12/site-packages/cudf/core/udf/udf_kernel_base.py:178, in ApplyKernelBase.get_kernel(self)
        177 def get_kernel(self):
    --> 178     return self._compile_or_get_kernel()
    
    File /usr/local/lib/python3.12/site-packages/cudf/core/udf/udf_kernel_base.py:195, in ApplyKernelBase._compile_or_get_kernel(self)
        193     return kernel, masked_or_scalar
    --> 195 kernel, scalar_return_type = self.compile_kernel()
        197 np_return_type = (
        198     numpy_support.as_dtype(scalar_return_type)
        199     if scalar_return_type.is_internal
        200     else scalar_return_type.np_dtype
        201 )
    
    File /usr/local/lib/python3.12/site-packages/cudf/core/udf/udf_kernel_base.py:144, in ApplyKernelBase.compile_kernel(self)
        143 with capture_nrt_usage:
    --> 144     return_type = self._get_udf_return_type()
        146 self.sig = self._construct_signature(return_type)
    
    File /usr/local/lib/python3.12/site-packages/cudf/core/udf/udf_kernel_base.py:111, in ApplyKernelBase._get_udf_return_type(self)
        110 with _CUDFNumbaConfig():
    --> 111     _, output_type = compile_udf(self.func, compile_sig)
        112 if isinstance(output_type, MaskedType):
    
    File /usr/local/lib/python3.12/site-packages/cudf/core/udf/utils.py:207, in compile_udf(udf, type_signature)
        205 # We haven't compiled a function like this before, so need to fall back to
        206 # compilation with Numba
    --> 207 ptx_code, return_type = cuda.compile_ptx_for_current_device(
        208     udf, type_signature, device=True
        209 )
        210 if not isinstance(return_type, MaskedType):
    
    File /usr/local/lib/python3.12/site-packages/numba/cuda/compiler.py:390, in compile_ptx_for_current_device(pyfunc, sig, debug, lineinfo, device, fastmath, opt, abi, abi_info)
        388 """Compile a Python function to PTX for a given signature for the current
        389 device's compute capabilility. See :func:`compile_ptx`."""
    --> 390 cc = get_current_device().compute_capability
        391 return compile_ptx(pyfunc, sig, debug=debug, lineinfo=lineinfo,
        392                    device=device, fastmath=fastmath, cc=cc, opt=opt,
        393                    abi=abi, abi_info=abi_info)
    
    File /usr/local/lib/python3.12/site-packages/numba/cuda/api.py:443, in get_current_device()
        442 "Get current device associated with the current thread"
    --> 443 return current_context().device
    
    File /usr/local/lib/python3.12/site-packages/numba/cuda/cudadrv/devices.py:220, in get_context(devnum)
        217 """Get the current device or use a device by device number, and
        218 return the CUDA context.
        219 """
    --> 220 return _runtime.get_or_create_context(devnum)
    
    File /usr/local/lib/python3.12/site-packages/numba/cuda/cudadrv/devices.py:138, in _Runtime.get_or_create_context(self, devnum)
        137 if attached_ctx is None:
    --> 138     return self._get_or_create_context_uncached(devnum)
        139 else:
    
    File /usr/local/lib/python3.12/site-packages/numba/cuda/cudadrv/devices.py:158, in _Runtime._get_or_create_context_uncached(self, devnum)
        156 else:
        157     # Get primary context for the active device
    --> 158     ctx = self.gpus[ac.devnum].get_primary_context()
        159     # Is active context the primary context?
    
    File /usr/local/lib/python3.12/site-packages/numba/cuda/cudadrv/devices.py:40, in _DeviceList.__getitem__(self, devnum)
         37 '''
         38 Returns the context manager for device *devnum*.
         39 '''
    ---> 40 return self.lst[devnum]
    
    IndexError: list index out of range
    
    The above exception was the direct cause of the following exception:
    
    ValueError                                Traceback (most recent call last)
    Cell In[3], line 2
          1 s = cudf.Series([1, 2, 3])
    ----> 2 s.apply(lambda x: x+1)
    
    File /usr/local/lib/python3.12/site-packages/cudf/core/series.py:2692, in Series.apply(self, func, convert_dtype, args, by_row, **kwargs)
       2689 elif by_row != "compat":
       2690     raise NotImplementedError("by_row is currently not supported.")
    -> 2692 result = self._apply(func, SeriesApplyKernel, *args, **kwargs)
       2693 result.name = self.name
       2694 return result
    
    File /usr/local/lib/python3.12/contextlib.py:81, in ContextDecorator.__call__.<locals>.inner(*args, **kwds)
         78 @wraps(func)
         79 def inner(*args, **kwds):
         80     with self._recreate_cm():
    ---> 81         return func(*args, **kwds)
    
    File /usr/local/lib/python3.12/site-packages/cudf/core/indexed_frame.py:3574, in IndexedFrame._apply(self, func, kernel_class, *args, **kwargs)
       3572     kernel, retty = kr.get_kernel()
       3573 except Exception as e:
    -> 3574     raise ValueError(
       3575         "user defined function compilation failed."
       3576     ) from e
       3578 # Mask and data column preallocated
       3579 ans_col = _return_arr_from_dtype(retty, len(self))
    
    ValueError: user defined function compilation failed.

    cc: @charlesfrye

  2. charlesfrye commented on Feb 2, 2026

    @charlesfrye

    Hmm, I think you may need to restart the Notebook after installing libraries that touch the driver.

  3. ncclementi commented on Apr 6, 2026

    @ncclementi
    ContributorAuthor

    I'm able to install now, like %uv pip install "cudf-cu13==26.2.*" and after restarting the kernel I can run cudf code.

    I'm having issues trying to run zero-code changes code. When I try to lead the %load_ext cudf.pandas the cell gets stuck in running, anthen I get a pop up with "Unexpected error" .

    My guess is that Modal notebooks, don't work like regular notebooks when it comes to the % magic.

    cc: @charlesfrye

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

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions