Skip to content

Commit

Permalink
Canonicalize the dtype
Browse files Browse the repository at this point in the history
Signed-off-by: Ming Huang <[email protected]>
  • Loading branch information
mingxu1067 committed Nov 3, 2023
1 parent 2ab34ee commit f3a8699
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions transformer_engine/jax/cpp_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def jax_dtype_to_te_dtype(jax_dtype):
"""
convert jax dtype to TE dtype
"""
jax_dtype = dtypes.canonicalize_dtype(jax_dtype)
if jax_dtype == jnp.float32:
return TEDType.kFloat32
if jax_dtype == jnp.float16:
Expand Down Expand Up @@ -1071,6 +1072,7 @@ def is_kernel_available(batch: int, heads: int, q_seqlen: int, k_seqlen: int,
"""Check Softmax kernel availability based on size"""
attn_batches = batch * heads

dtype = dtypes.canonicalize_dtype(dtype)
if (dtype in [jnp.float16, jnp.bfloat16]
and 16 < k_seqlen <= SoftmaxPrimitive.max_k_seqlen_supported
# k_seqlen must be 16 ~ 4096
Expand Down Expand Up @@ -1225,6 +1227,7 @@ def is_kernel_available(batch: int, heads: int, q_seqlen: int, k_seqlen: int,
"""Check Softmax kernel availability based on size"""
attn_batches = batch * heads

dtype = dtypes.canonicalize_dtype(dtype)
if (dtype in [jnp.float16, jnp.bfloat16]
and 16 < k_seqlen <= SoftmaxPrimitive.max_k_seqlen_supported
# k_seqlen must be 16 ~ 4096
Expand Down Expand Up @@ -1441,6 +1444,7 @@ def is_kernel_available(batch: int, heads: int, q_seqlen: int, k_seqlen: int,
"""Check Softmax kernel availability based on size"""
attn_batches = batch * heads

dtype = dtypes.canonicalize_dtype(dtype)
if (dtype in [jnp.float16, jnp.bfloat16]
and 16 < k_seqlen <= SoftmaxPrimitive.max_k_seqlen_supported
# k_seqlen must be 16 ~ 4096
Expand Down

0 comments on commit f3a8699

Please sign in to comment.