Preserve JAX decorator metadata#6427
Conversation
Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
|
| Filename | Overview |
|---|---|
| dali/python/nvidia/dali/plugin/jax/fn/_jax_function_impl.py | Adds @functools.wraps(function) to dali_callback inside the jax_function decorator, correctly preserving name, doc, wrapped, and inspect.signature for the decorated JAX callback. Copyright year updated to 2024-2026. |
| dali/python/nvidia/dali/plugin/jax/iterator.py | Adds @functools.wraps(func) to create_iterator inside data_iterator_decorator. This correctly preserves function metadata but hides the checkpoints=None parameter from inspect.signature on the decorated result. Copyright year updated to 2023-2026. |
| dali/python/nvidia/dali/plugin/jax/init.pyi | New PEP 561 stub for the jax plugin package. Correctly models both the direct-call and configured-decorator overloads of data_iterator with appropriate return types. Exports all with the three public symbols. |
| dali/python/nvidia/dali/plugin/jax/fn/init.pyi | New PEP 561 stub for jax.fn. Defines JaxCallback and DaliCallback protocols and dual overloads of jax_function. Does not define all (unlike the parent stub), but this is harmless in a .pyi file. |
| dali/test/python/jax_plugin/test_jax_operator.py | Adds test_jax_function_preserves_function_metadata with the required @restrict_python_version(3, 9) guard. Test correctly checks wrapped, inspect.signature, and inspect.getdoc. Copyright year updated to 2024-2026. |
| dali/test/python/jax_plugin/test_iterator_decorator.py | Adds test_dali_iterator_decorator_preserves_function_metadata checking wrapped, signature equality, and docstring propagation. No Python version guard needed (data_iterator does not require JAX >= 0.4.16 directly). Copyright year updated to 2023-2026. |
Sequence Diagram
sequenceDiagram
participant User
participant jax_function
participant decorator
participant dali_callback
participant functools.wraps
User->>jax_function: "@dax.fn.jax_function (direct)"
jax_function->>decorator: decorator(function)
decorator->>functools.wraps: wraps(function)(dali_callback)
functools.wraps-->>dali_callback: copies __name__, __doc__, __wrapped__, __annotations__
decorator-->>User: dali_callback [looks like original JAX fn]
User->>jax_function: "@dax.fn.jax_function(num_outputs=2) (configured)"
jax_function-->>User: decorator (closure over num_outputs)
User->>decorator: decorator(function)
decorator->>functools.wraps: wraps(function)(dali_callback)
functools.wraps-->>dali_callback: copies metadata
decorator-->>User: dali_callback [looks like original JAX fn]
Note over User,dali_callback: IDE sees original JAX callback signature via __wrapped__
Note over User,dali_callback: Runtime accepts only *args: DataNode (DALI nodes)
Reviews (3): Last reviewed commit: "Address JAX metadata review feedback" | Re-trigger Greptile
Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
0dc4c3c to
92ef386
Compare
|
!build |
|
CI MESSAGE: [59134975]: BUILD STARTED |
|
CI MESSAGE: [59134975]: BUILD FAILED |
|
CI MESSAGE: [59134975]: BUILD PASSED |
Category:
Other
Description:
Improve documentation and IDE support for JAX-decorated functions.
The JAX
jax_functionanddata_iteratordecorators now preserve the decorated function metadata. Public PEP 561 stubs describe both direct and configured decorator forms, enabling IDE completion and static type checking.Additional information:
Affected modules and functionalities:
nvidia.dali.plugin.jax.fn.jax_functionnvidia.dali.plugin.jax.data_iteratorKey points relevant for the review:
functools.wrapspreserves the original callable signature, docstring, annotations, and__wrapped__chain without changing operator execution.Tests:
test_jax_function_preserves_function_metadatatest_dali_iterator_decorator_preserves_function_metadataChecklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: DALI-3680