Skip to content

Ascend - #63

Merged
Hchnr merged 27 commits into
mainfrom
ascend
Jun 1, 2026
Merged

Ascend#63
Hchnr merged 27 commits into
mainfrom
ascend

Conversation

@Hchnr

@Hchnr Hchnr commented Jun 1, 2026

Copy link
Copy Markdown
Owner

No description provided.

Hchnr added 27 commits May 29, 2026 14:56
…am for FlagGems integration

- Add csrc/aten/backends/ascend/acl_stream.h: centralized singleton ACL stream
- Add csrc/runtime/flagos_stream_api.cc: exports FlagOS_GetCurrentStream() C API
- Update op_api_common.h to use shared GetDefaultAclStream()
- Update CMakeLists.txt to auto-detect FLAGGEMS_DIR from installed flag_gems package
… dependency

liboperators.so (FlagGems) needs FlagOS_GetCurrentStream which was in torch_fl._C.
This creates a circular load dependency. Solution: build it as a separate
libflagos_stream.so loaded with RTLD_GLOBAL before _C.
…ck pointer bug

- Set GEMS_VENDOR=ascend and provide torch.npu/torch_npu shims so FlagGems
  uses ASCEND codegen config (prefer_block_pointer=False)
- Route most ops through flagos_python (FlagGems Triton) in ascend config
- Keep embedding/embedding_dense_backward on ascend C++ backend
- Keep factory ops (new_ones, zeros, etc.) on ascend C++ backend
FlagGems has a deep lazy import chain (fused → FLA → utils → models → sqlalchemy)
that can exceed Python's recursion limit when triggered inside PyTorch dispatch.
Import it during _lazy_init() to avoid this.
1. python_op_caller.cc: OptionalIntArrayRefToPython now passes empty arrays
   as [] instead of None, so FlagGems sum_dim_comm takes the dim==[] path
   (calls local sum() directly) instead of the dim==None path (calls
   torch.sum which re-dispatches → infinite recursion).

2. sum.cc: Normalize dim=None to dim=[] before calling FlagGems sum_dim.

3. flagos/__init__.py: Eagerly import flag_gems during _lazy_init() to
   avoid deep import chain (fused→FLA→utils→models→sqlalchemy) exceeding
   Python recursion limit when triggered inside PyTorch dispatch stack.

4. Revert sum.dim_IntList back to flagos_python (no longer needs ascend).
When FLAGGEMS_PYTHON=1 and FLAGGEMS_KERNEL=0, only the Python wrappers
(python_op_caller + python_wrapper/*.cc) are compiled. This avoids the
need for FlagGems C++ library (liboperators.so) when only using FlagGems
via Python dispatch.

Build command:
  ACCELERATOR=ascend FLAGGEMS_PYTHON=1 FLAGGEMS_KERNEL=0 CUDA_KERNEL=0 \
  ASCEND_KERNEL=1 CMAKE_BUILD_PARALLEL_LEVEL=32 pip install --no-build-isolation -e .
…/mean to ascend

- sum: When dim is None/empty, call flag_gems.ops.sum directly instead of
  sum_dim. FlagGems sum_dim with dim=[] fails because Python () != [] check.
  This fixes 'grad can be implicitly created only for scalar outputs' in
  silu_backward, embedding_dense_backward, and slice_backward tests.
- acos: Route to ascend backend (triton-ascend compiler error)
- mean.dim: Route to ascend backend (FlagGems non-inner dim uses CUDA context)
- Add CallPythonOp_TD helper for (Tensor, optional<dtype>) signature
@Hchnr
Hchnr merged commit 2f5822c into main Jun 1, 2026
1 check failed
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