Skip to content

Commit fa61353

Browse files
committed
Remove star imports for the top-level module
1 parent db14b4b commit fa61353

10 files changed

Lines changed: 374 additions & 368 deletions

src/flag_gems/__init__.py

Lines changed: 315 additions & 316 deletions
Large diffs are not rendered by default.

src/flag_gems/ops/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,12 @@
242242
"add",
243243
"add_",
244244
"addcdiv",
245+
"addcmul",
245246
"addmm",
246247
"addmm_out",
247248
"addmv",
248249
"addmv_out",
250+
"addr",
249251
"all",
250252
"all_dim",
251253
"all_dims",
@@ -423,6 +425,7 @@
423425
"ones",
424426
"ones_like",
425427
"pad",
428+
"per_token_group_quant_fp8",
426429
"polar",
427430
"pow_scalar",
428431
"pow_tensor_scalar",
@@ -441,7 +444,6 @@
441444
"reciprocal_",
442445
"relu",
443446
"relu_",
444-
"addcmul",
445447
"softplus",
446448
"remainder",
447449
"remainder_",
@@ -506,10 +508,8 @@
506508
"upsample_nearest2d",
507509
"var_mean",
508510
"vdot",
509-
"addr",
510511
"vector_norm",
511512
"vstack",
512-
"per_token_group_quant_fp8",
513513
"SUPPORTED_FP8_DTYPE",
514514
"weight_norm_interface",
515515
"weight_norm_interface_backward",

tests/accuracy_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import torch
77

88
import flag_gems
9+
from flag_gems import testing
910

1011
from .conftest import QUICK_MODE, TO_CPU
1112

@@ -205,14 +206,14 @@ def to_cpu(res, ref):
205206

206207
def gems_assert_close(res, ref, dtype, equal_nan=False, reduce_dim=1, atol=1e-4):
207208
res = to_cpu(res, ref)
208-
flag_gems.testing.assert_close(
209+
testing.assert_close(
209210
res, ref, dtype, equal_nan=equal_nan, reduce_dim=reduce_dim, atol=atol
210211
)
211212

212213

213214
def gems_assert_equal(res, ref, equal_nan=False):
214215
res = to_cpu(res, ref)
215-
flag_gems.testing.assert_equal(res, ref, equal_nan=equal_nan)
216+
testing.assert_equal(res, ref, equal_nan=equal_nan)
216217

217218

218219
def unsqueeze_tuple(t, max_len):

tests/test_attention_ops.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import triton
1010

1111
import flag_gems
12+
from flag_gems import fused
1213

1314
try:
1415
import vllm.vllm_flash_attn.flash_attn_interface as _vllm # noqa: F401
@@ -1186,7 +1187,7 @@ def test_concat_and_cache_mla(
11861187
else:
11871188
ref_kv_cache = to_reference(ref_temp)
11881189
with flag_gems.use_gems():
1189-
flag_gems.concat_and_cache_mla(
1190+
fused.concat_and_cache_mla(
11901191
kv_c, k_pe, kv_cache, slot_mapping, kv_cache_dtype, scale
11911192
)
11921193

@@ -1295,7 +1296,7 @@ def test_reshape_and_cache(
12951296
cloned_value_cache = value_cache.clone()
12961297

12971298
# Call the reshape_and_cache kernel.
1298-
flag_gems.reshape_and_cache(
1299+
fused.reshape_and_cache(
12991300
key,
13001301
value,
13011302
key_cache,
@@ -1444,7 +1445,7 @@ def test_reshape_and_cache_flash(
14441445
cloned_value_cache = value_cache.clone()
14451446

14461447
# Call the reshape_and_cache kernel.
1447-
flag_gems.reshape_and_cache_flash(
1448+
fused.reshape_and_cache_flash(
14481449
key,
14491450
value,
14501451
key_cache,
@@ -1580,7 +1581,7 @@ def ref_mla(
15801581
dv,
15811582
causal,
15821583
)
1583-
res_out = flag_gems.flash_mla(
1584+
res_out = fused.flash_mla(
15841585
q,
15851586
block_table,
15861587
blocked_k,

tests/test_binary_pointwise_ops.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import torch
88

99
import flag_gems
10+
from flag_gems import fused
1011

1112
from .accuracy_utils import (
1213
ALL_FLOAT_DTYPES,
@@ -977,7 +978,7 @@ def test_accuracy_gelu_and_mul(shape, approximate, dtype):
977978
torch.nn.functional.gelu(ref_inp1, approximate=approximate), ref_inp2
978979
)
979980
with flag_gems.use_gems():
980-
res_out = flag_gems.gelu_and_mul(inp1, inp2, approximate)
981+
res_out = fused.gelu_and_mul(inp1, inp2, approximate)
981982

982983
out_grad = torch.randn_like(res_out)
983984
ref_grad = to_reference(out_grad, True)
@@ -1389,7 +1390,7 @@ def test_accuracy_silu_and_mul(shape, dtype):
13891390

13901391
ref_out = torch.mul(torch.nn.functional.silu(ref_inp1), ref_inp2)
13911392
with flag_gems.use_gems():
1392-
res_out = flag_gems.silu_and_mul(inp1, inp2)
1393+
res_out = fused.silu_and_mul(inp1, inp2)
13931394

13941395
out_grad = torch.randn_like(res_out)
13951396
ref_grad = to_reference(out_grad, True)

tests/test_blas_ops.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import torch
77

88
import flag_gems
9+
from flag_gems import fused, ops
910

1011
from .accuracy_utils import (
1112
FLOAT_DTYPES,
@@ -143,7 +144,7 @@ def test_accuracy_baddbmm(M, N, K, scalar, dtype):
143144
alpha = beta = scalar
144145

145146
ref_out = torch.baddbmm(ref_bias, ref_mat1, ref_mat2, alpha=alpha, beta=beta)
146-
res_out = flag_gems.baddbmm(bias, mat1, mat2, alpha=alpha, beta=beta)
147+
res_out = ops.baddbmm(bias, mat1, mat2, alpha=alpha, beta=beta)
147148

148149
gems_assert_close(res_out, ref_out, dtype, reduce_dim=K)
149150

@@ -174,7 +175,7 @@ def test_accuracy_baddbmm_backward(M, N, K, scalar, dtype):
174175
alpha = beta = scalar
175176

176177
ref_out = torch.baddbmm(ref_bias, ref_mat1, ref_mat2, alpha=alpha, beta=beta)
177-
res_out = flag_gems.baddbmm(bias, mat1, mat2, alpha=alpha, beta=beta)
178+
res_out = ops.baddbmm(bias, mat1, mat2, alpha=alpha, beta=beta)
178179

179180
out_grad = torch.randn_like(res_out)
180181
ref_grad = to_reference(out_grad, True)
@@ -303,7 +304,7 @@ def test_accuracy_outer(M, N, dtype):
303304
ref_inp2 = to_reference(inp2, True)
304305

305306
ref_out = torch.outer(ref_inp1, ref_inp2)
306-
res_out = flag_gems.outer(inp1, inp2)
307+
res_out = fused.outer(inp1, inp2)
307308
gems_assert_close(res_out, ref_out, dtype)
308309

309310
out_grad = torch.randn_like(res_out)

tests/test_norm_ops.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import torch
77

88
import flag_gems
9+
from flag_gems import fused, ops
910

1011
from .accuracy_utils import (
1112
FLOAT_DTYPES,
@@ -366,7 +367,7 @@ def test_accuracy_instancenorm(
366367
eps=eps,
367368
)
368369

369-
res_out = flag_gems.instance_norm(
370+
res_out = fused.instance_norm(
370371
inp,
371372
weight=weight,
372373
bias=bias,
@@ -544,7 +545,7 @@ def _torch_rms_norm(x, weight, eps):
544545
return weight * hidden_states
545546

546547
ref_out = _torch_rms_norm(ref_inp, weight=ref_weight, eps=eps)
547-
res_out = flag_gems.rms_norm(inp, list(layer_shape), weight=weight, eps=eps)
548+
res_out = ops.rms_norm(inp, list(layer_shape), weight=weight, eps=eps)
548549

549550
res_grad = torch.tensor(
550551
np_grad, dtype=dtype, device=flag_gems.device, requires_grad=True
@@ -587,7 +588,7 @@ def test_accuracy_skip_layernorm(shape, dtype):
587588
bias=ref_bias,
588589
eps=eps,
589590
)
590-
res_out = flag_gems.skip_layer_norm(
591+
res_out = fused.skip_layer_norm(
591592
inp, residual, list(layer_shape), weight=weight, bias=bias, eps=eps
592593
)
593594

@@ -624,7 +625,7 @@ def _torch_fused_add_rms_norm(x, residual, weight, eps):
624625
eps=eps,
625626
)
626627

627-
res_out, res_new_residual = flag_gems.fused_add_rms_norm(
628+
res_out, res_new_residual = fused.fused_add_rms_norm(
628629
inp, residual, list(layer_shape), weight=weight, eps=eps
629630
)
630631

0 commit comments

Comments
 (0)