Skip to content

Commit f1ab525

Browse files
author
zhangyue
committed
style: fix code convention violations (round 3)
- C4: lowercase "rope" in ATB assert messages - G4: backtick-fence `VariantPack`, `rotaryCoeff`, `sparseMode`, `hostData` - G4: backtick-fence identifiers in Python test comments - P4: add blank line before `if` in test_rms_norm_precision.py
1 parent 255ba00 commit f1ab525

8 files changed

Lines changed: 19 additions & 18 deletions

File tree

src/ascend/custom_kernel/csrc/ops/rms_norm/test/test_rms_norm_precision.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def _compute_metrics(out, ref):
6868

6969
ref_abs = ref.float().abs()
7070
nonzero = ref_abs > 1e-10
71+
7172
if nonzero.any():
7273
rel_err = diff[nonzero] / ref_abs[nonzero]
7374
max_rel_err = rel_err.max().item()

src/ascend/custom_kernel/tests/test_add_rms_norm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_add_rms_norm_correctness(dtype, shape):
7777
f"{(x_out_npu.cpu() - x_out_ref).abs().max().item()}"
7878
)
7979

80-
# Check y = rms_norm(x_out) * weight.
80+
# Check `y = rms_norm(x_out) * weight`.
8181
rtol = 1e-3 if dtype == torch.float16 else 1e-5
8282
atol = 1e-3 if dtype == torch.float16 else 1e-5
8383
assert torch.allclose(y_npu.cpu(), y_ref, rtol=rtol, atol=atol), (

src/ascend/custom_kernel/tests/test_rms_norm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
import torch
55
import torch_npu
6-
import ascend_kernel # noqa: F401 Loads libascend_kernel.so into torch.ops.npu.
6+
import ascend_kernel # noqa: F401 Loads `libascend_kernel.so` into `torch.ops.npu`.
77

88

99
def rms_norm_ref(x: torch.Tensor, weight: torch.Tensor, eps: float) -> torch.Tensor:

src/ascend/flash_attention/kernel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ inline aclIntArray* cumSeqLengths(const Tensor& cu_seqlens,
7777
}
7878

7979
// Allocate a 2048x2048 lower-triangular UINT8 causal mask on device.
80-
// Required for sparseMode >= 2.
80+
// Required for `sparseMode` >= 2.
8181
inline aclTensor* makeCausalMask(void** mask_buf, aclrtStream stream) {
8282
constexpr int64_t kMaskDim = 2048;
8383
const int64_t mask_elems = kMaskDim * kMaskDim;

src/ascend/paged_attention/kernel_atb.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace infini::ops {
3434
// synchronous D2H copies for these two small tensors in each call.
3535
// All other tensors are device-only.
3636
//
37-
// ATB VariantPack layout (BSND with S=1):
37+
// ATB `VariantPack` layout (BSND with S=1):
3838
// inTensors[0] = query [B, N, D]
3939
// inTensors[1] = key_cache [num_blocks, block_size, Nkv, D]
4040
// inTensors[2] = value_cache [num_blocks, block_size, Nkv, D]
@@ -154,7 +154,7 @@ class Operator<PagedAttention, Device::Type::kAscend, 0>
154154
}
155155

156156
private:
157-
// Build the ATB VariantPack.
157+
// Build the ATB `VariantPack`.
158158
//
159159
// Query and output are 3D [B, N, D] (BSND with S=1 for decode).
160160
// Block table and context lens carry both `deviceData` and
@@ -183,12 +183,12 @@ class Operator<PagedAttention, Device::Type::kAscend, 0>
183183
atb::Tensor t_value_cache = ascend::toAtbTensor(kv_cache_shape_, acl_dt_,
184184
value_cache_data, kv_bytes);
185185

186-
// Block table [B, max_blocks] — with hostData for `aclIntArray*`.
186+
// Block table [B, max_blocks] — with `hostData` for `aclIntArray*`.
187187
atb::Tensor t_block_table = ascend::toAtbTensor(
188188
block_table_shape_, bt_dt_, block_table_data, bt_host_bytes_);
189189
t_block_table.hostData = bt_host_;
190190

191-
// Context lens [B] — with hostData for `aclIntArray*`.
191+
// Context lens [B] — with `hostData` for `aclIntArray*`.
192192
atb::Tensor t_context_lens = ascend::toAtbTensor(
193193
context_lens_shape_, sl_dt_, seq_lens_data, sl_host_bytes_);
194194
t_context_lens.hostData = sl_host_;

src/ascend/reshape_and_cache/kernel_atb.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace infini::ops {
2929
// `aclnnInplaceIndexCopy` path (index 0, ~35 us).
3030
//
3131
// The ATB operation is created once in the constructor. Setup is called
32-
// before each Execute to bind the VariantPack.
32+
// before each `Execute` to bind the `VariantPack`.
3333
//
3434
// NOTE: `ReshapeAndCacheParam` requires int32 `slot_mapping`. When the
3535
// caller passes int64 (the default in PyTorch / vLLM), this operator casts
@@ -57,7 +57,7 @@ class Operator<ReshapeAndCache, Device::Type::kAscend, 2>
5757
int64_t hs = static_cast<int64_t>(head_size_);
5858
int64_t T = static_cast<int64_t>(num_tokens_);
5959

60-
// Cache shapes for rebuilding VariantPack on each call.
60+
// Cache shapes for rebuilding `VariantPack` on each call.
6161
kv_shape_ = {num_blocks, bs, nkv, hs};
6262
key_shape_ = {T, nkv, hs};
6363
slot_shape_ = {T};
@@ -134,7 +134,7 @@ class Operator<ReshapeAndCache, Device::Type::kAscend, 2>
134134
const_cast<void*>(value.data()),
135135
kv_cache_out.data(), slot32_ptr);
136136

137-
// Setup binds the VariantPack and computes workspace requirements.
137+
// `Setup` binds the `VariantPack` and computes workspace requirements.
138138
uint64_t ws_size = 0;
139139
atb::Status s = op_->Setup(vp, ws_size, ctx);
140140
assert(s == atb::NO_ERROR &&
@@ -154,7 +154,7 @@ class Operator<ReshapeAndCache, Device::Type::kAscend, 2>
154154
}
155155

156156
private:
157-
// Build the ATB VariantPack for this operation.
157+
// Build the ATB `VariantPack` for this operation.
158158
//
159159
// ATB `ReshapeAndCache` expects 5 inputs and 2 outputs:
160160
// inTensors[0] = key [num_tokens, num_kv_heads, head_size]

src/ascend/rotary_embedding/kernel_atb.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace infini::ops {
4444
//
4545
// Restrictions:
4646
// - rotary_dim must equal head_size (full rotation only).
47-
// - is_neox_style must be true (rotaryCoeff=2).
47+
// - is_neox_style must be true (`rotaryCoeff`=2).
4848
// - fp16 only (ATB inference constraint).
4949
template <>
5050
class Operator<RotaryEmbedding, Device::Type::kAscend, 1>
@@ -74,7 +74,7 @@ class Operator<RotaryEmbedding, Device::Type::kAscend, 1>
7474
aclrtMemcpy(cache_host.data(), table_bytes, cos_sin_cache.data(),
7575
table_bytes, ACL_MEMCPY_DEVICE_TO_HOST);
7676

77-
// ATB Rope with rotaryCoeff=2 expects cos/sin of shape [S, D].
77+
// ATB Rope with `rotaryCoeff`=2 expects cos/sin of shape [S, D].
7878
// Neox-style expansion: [c0..c_{hD-1}, c0..c_{hD-1}].
7979
std::vector<uint8_t> cos_host(table_bytes);
8080
std::vector<uint8_t> sin_host(table_bytes);
@@ -208,7 +208,7 @@ class Operator<RotaryEmbedding, Device::Type::kAscend, 1>
208208
ACL_MEMCPY_HOST_TO_DEVICE, stream);
209209
}
210210

211-
// Build ATB VariantPack with 5 inputs + 2 outputs.
211+
// Build ATB `VariantPack` with 5 inputs + 2 outputs.
212212
atb::Context* ctx = ascend::getAtbContext(stream);
213213

214214
uint64_t q_bytes = static_cast<uint64_t>(T * hiddenQ) * elem_size_;
@@ -233,7 +233,7 @@ class Operator<RotaryEmbedding, Device::Type::kAscend, 1>
233233
uint64_t ws_size = 0;
234234
atb::Status s = op_->Setup(vp, ws_size, ctx);
235235

236-
assert(s == atb::NO_ERROR && "ATB Rope setup failed");
236+
assert(s == atb::NO_ERROR && "ATB rope setup failed");
237237

238238
uint8_t* ws_ptr = nullptr;
239239

@@ -244,7 +244,7 @@ class Operator<RotaryEmbedding, Device::Type::kAscend, 1>
244244

245245
s = op_->Execute(vp, ws_ptr, ws_size, ctx);
246246

247-
assert(s == atb::NO_ERROR && "ATB Rope execute failed");
247+
assert(s == atb::NO_ERROR && "ATB rope execute failed");
248248
}
249249

250250
private:
@@ -260,7 +260,7 @@ class Operator<RotaryEmbedding, Device::Type::kAscend, 1>
260260

261261
mutable size_t pos_buf_size_ = 0;
262262

263-
// Cached shapes for ATB VariantPack.
263+
// Cached shapes for ATB `VariantPack`.
264264
std::vector<int64_t> q_2d_shape_;
265265

266266
std::vector<int64_t> k_2d_shape_;

tests/test_add_rms_norm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _add_rms_norm(x1, x2, gamma, *, eps=1e-6, y_out=None, x_out=None,
7575
implementation_index=implementation_index,
7676
)
7777

78-
# Concatenate both outputs into a single flat tensor for allclose comparison.
78+
# Concatenate both outputs into a single flat tensor for `allclose` comparison.
7979
return torch.cat([y_out.contiguous().flatten(), x_out.contiguous().flatten()])
8080

8181

0 commit comments

Comments
 (0)