Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Align the Ascend backend with the contracts the transformer tests already encode.
epsandoffsetwithtl.cast, and read the tensor dtype from the pointer.torch.compilespecializes those scalars to constexpr, which has no.to(), and a host dtype constexpr is emitted as a bare name on NPU.loss_dtypeandin_place. Per-token loss is accumulated in fp32 and cast back to the input dtype unlessloss_dtype=torch.float32. A second backward is rejected after an in-place scale. Plainreduction="none"scales the existing Triton kernel's stored gradient once, so the result matches that kernel bitwise. The masked tail of a weighted, label-smoothed row is dropped before the sum.The CUDA kernels are unchanged. Backends other than
nvidia-tritonandascend-tritonstill rejectloss_dtypeandin_place.Details
src/liger_kernel/transformers/cross_entropy.pyonly addsascend-tritonto the existing allowlist. That check runs only whenloss_dtypeis set orin_placeis true.Plain
reduction="none"backward callsliger_kernel.ops.cross_entropy.cross_entropy_forwardand multiplies its stored gradient by the upstream row scale, then rounds once. Mean and sum stay on the Ascend backward kernel. Recomputing softmax in the Ascend kernel differs by about one ulp from the stored gradient, which failstorch.equal.Testing Done
ruff checkandruff format --checkon the six touched filesmake testmake test-convergenceOn one idle NPU:
loss_dtype, per-row grad,matches_torch, in-place second backward,retain_graph) and Qwen3.5 vision RoPE: 104 passed.