You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bind fill_next_token_bitmask against nb::ndarray (#338)
Nanobind has built-in support for the DLPack standard, which allows us
to take anything adhering to the DLPack spec here rather than just
PyTorch objects. See here:
https://nanobind.readthedocs.io/en/latest/ndarray.html
This does add a dependency on numpy, but only for a single type, which
does seem a little overkill. If I push on
#233 a little bit though, we
should only need these definitions in the stubfiles, and will be
unneeded for the `.py` files. So ideally this is a temporary dependency.
My goal is to reduce the dependency on PyTorch a bit by making the code
more general. I don't know if (or even think) that we can remove it
entirely, but this seems worthwhile to do.
The annotation on the `nb::ndarray` class will actually check at runtime
that the parameter has the desired properties (in this case, it's on the
CPU and is an int32_t), and will simply fail to call the function if
not. This might be a slight breaking change in terms of what exception
actually gets raised, but I think this is reasonable.
A few related changes:
- I've converted a few function signatures to take DLTensors by `const&`
instead of `*`, didn't see a good reason for it.
- Added an anonymous namespace in `nanobind.cc` just to keep things
hygenic.
---------
Signed-off-by: Ubospica <[email protected]>
Co-authored-by: Ubospica <[email protected]>
Co-authored-by: Yixin Dong <[email protected]>
0 commit comments