Revamp metadata writing and add kernel id#471
Conversation
* Strongly type the kernel identifier within kernel-builder. * Write the kernel identifier to the kernel metadata. * Make noarch kernels include the backend in the identifier as well. * Fix tvm-ffi build-time metadata update to include the arches. * Rename build-time metadata update script to be more general. * Run the build-time metadata update script for non-CUDA/ROCm backends. This is not strictly necessary now, but allows us to add other metadata bits in the future. * Add a build hook that validates the metadata after build using the Rust-side data structures. This ensures that build-time changes are valid and schema-conforming.
This change adds support for kernel id metadata and uses the kernel id (when present) as the identifier in the Python module table in place of the path hash.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
|
||
| _OPS_NAME = _find_ops_name() | ||
|
|
||
| ops = getattr(torch.ops, _OPS_NAME) |
There was a problem hiding this comment.
Help me unpack this a little. _find_ops_name() seems to have placeholders that are not fully resolved at this point. Same for add_op_namespace_prefix()
There was a problem hiding this comment.
These are filled by kernel-builder:
There was a problem hiding this comment.
Oh cool. Perhaps a small explainer comment could helpful for future reference and it's not immediately clear where this will be used. No strong opinions.
kernels-data is going to be used by `kernels`, so we need to make sure that we can also read kernels that do not have an id yet.
| path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path)).value) | ||
| module_name = f"{module_name}_{path_hash}" | ||
| spec = importlib.util.spec_from_file_location(module_name, file_path) | ||
| if metadata.id is None: |
There was a problem hiding this comment.
Should a warning be thrown in line with the previous warning?
f"Kernel loaded from `{variant_path}` does not have metadata,"
Or is it a fair assumption that LoadedKernel can't always guarantee metadata.id?
There was a problem hiding this comment.
The warning will already by emitted by:
kernels/kernels/src/kernels/metadata.py
Line 23 in 793d303
Changes in kernel-builder:
Changes in kernels:
sys.modules, avoiding the path hash.