Skip to content

Gen pyi test - #5

Draft
cleonard530 wants to merge 24 commits into
migrate_pybind_to_torch_libraryfrom
gen_pyi_test
Draft

cleonard530 wants to merge 24 commits into
migrate_pybind_to_torch_libraryfrom
gen_pyi_test

Conversation

@cleonard530

@cleonard530 cleonard530 commented Jul 22, 2026

Copy link
Copy Markdown
Owner

This is just to show the difference between _C.pyi before and after move to TORCH_LIBRARY.

Creating this PR because writing comments on commits keep disappearing.

Checkout the latest commit to see the _C.pyi changes 66a9b5f

Originally, this file was generated from the C++ function signatures. It is now generated from the TORCH_LIBRARY schemas, with default argument values taken from _C.py.

The differences fall into the following categories:

  1. Improved type hints.
  2. Parameter name changes. The previous generator used the C++ parameter names rather than the Python parameter names, which caused the .pyi signatures to differ from the actual Python API. The new generator uses the correct Python parameter names, so the generated .pyi file now matches the keyword arguments accepted by the Python bindings. This does not change runtime behavior or break backwards compatibility; it simply makes the type stubs accurate.
  3. Quote style changes for default values. TORCH_LIBRARY schemas represent string default values using single quotes (') instead of double quotes (").
  4. More precise signatures for previously anonymous functions. Previously, lambda functions were emitted with generic signatures (*args, **kwargs). To register these functions with TORCH_LIBRARY, they were replaced with named functions and their arguments have been parsed like the rest of the functions. As a result, the generated .pyi file now contains more informative and accurate function signatures.
  5. A new _slice_symm_buffer_for_mega_moe function has been added.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
… match what was in the legacy code

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…helper code from generate_pyi.py

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…updates so I updated it to inlcude the type hints

Signed-off-by: Chris Leonard <chleonar@redhat.com>
Signed-off-by: Chris Leonard <chleonar@redhat.com>
…ybind default arguments are no longer there

Signed-off-by: Chris Leonard <chleonar@redhat.com>
Signed-off-by: Chris Leonard <chleonar@redhat.com>
…ther minor formatting issues. Also added comments with examples to help describe each step. These will be removed (as well as main()) in a followup commit, but wanted them here for reference

Signed-off-by: Chris Leonard <chleonar@redhat.com>
Signed-off-by: Chris Leonard <chleonar@redhat.com>
Signed-off-by: Chris Leonard <chleonar@redhat.com>
Signed-off-by: Chris Leonard <chleonar@redhat.com>
…TORCH_LIBRARY; deep_gemm/_C.py can keep using torch.ops.load_library.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
… function that was leftover from migration, replaces torch_compat with torch/all.h, and updated the sm120 files to use torch/all.h instead of torch/python.h
…_library_macros

- Drop torch_library_macros.hpp; register ops via TORCH_FN directly and rename
  torch_library_utils namespace to torch_utils.
- Use at::ScalarType/torch.dtype for logits_dtype instead of int + _SCALAR_TYPE dict.
- Align schema/wrapper param names with C++ impl (fused_kv_cache,
  activation_clamp_opt, *_tuple/*_tuple_opt), propagated to _C.py, mega/__init__.py,
  and tests.
- Prefix slice_symm_buffer_for_mega_moe with _ to mark it private.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
Signed-off-by: Chris Leonard <chleonar@redhat.com>
…o align it with the C++ names

Signed-off-by: Chris Leonard <chleonar@redhat.com>
fp8_fp4_mega_moe and bf16_mega_moe both write into this tensor via a device-side red.add reduction (accumulating per-expert recv counts across calls), but the TORCH_LIBRARY schema declared it as immutable (Tensor?). Fix by annotating it Tensor(cumulative_local_expert_recv_stats!)?.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…filenames on release uploads. Bump the floor to cp310, which every torch version in the matrix (2.4-2.8) already supports.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…as. These were declared optional but the C++ impl always called unconditionally, so would have crashed anyway; the Python wrappers already default to a concrete tuple.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…n by having get_symm_buffer_size_for_mega_moe return the computed layout as an int[] alongside num_bytes, which _slice_symm_buffer_for_mega_moe now reuses instead of rederiving it (and its num_sms-dependent ring sizing) from the original args a second time.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…params like recipe/head_splits, so the schema itself is the source of truth for stub generation instead of a hand-maintained per-name promotion table in generate_pyi.py. Add an _as_int_list wrapper helper so int[N]'s scalar-broadcasting behavior can't silently convert a bad scalar argument into a repeated list.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…le-factor pairs like q/q_sf, replacing the special-cased _apply_q_qsf_merge, and sort the csrc/ file scan so op ordering in the generated stub no longer shuffles across machines/checkouts. Also drop sanitize_param_name, since it could only keep the .pyi syntactically valid and not guarantee the stub's keyword name actually matches the real wrapper at runtime.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
Signed-off-by: Chris Leonard <chleonar@redhat.com>
Signed-off-by: Chris Leonard <chleonar@redhat.com>
@cleonard530
cleonard530 force-pushed the migrate_pybind_to_torch_library branch from 61073b9 to 90d0764 Compare September 4, 2026 19:08
@cleonard530
cleonard530 force-pushed the migrate_pybind_to_torch_library branch from 90d0764 to 343826c Compare September 9, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant