python-cut-cross-entropy
CLEAN
maintainer Smoolak
0 votes
scanned 2026-09-21 00:26:32.109917
Triggered rules
Clean
AI review downgraded a static finding
llm_review
The static rules flagged this LOW, but an AI model (qwen/qwen3-235b-a22b-2507) reviewed the full PKGBUILD and judged it CLEAN (confidence 95%): The package builds from a pinned commit of the official GitHub repository, applies a minor patch for test correctness, and installs a wheel built locally; no untrusted remote code execution or supply-chain risks are present.
1 higher static finding superseded - not the current verdict (shown for transparency)
Low
Few votes, recently uploaded
zero_votes_recent
Uploaded within the last 14 days with 2 or fewer community votes — little peer review so far.
PKGBUILD
1
# Maintainer: Smoolak <smoolak@gmail.com>
2
3
pkgname=python-cut-cross-entropy
4
_pkgname=cut_cross_entropy
5
pkgver=25.9.3
6
pkgrel=3
7
pkgdesc="A fast implementation of cross entropy loss using cut method with Triton kernels"
8
arch=('any')
9
url="https://github.com/apple/ml-cross-entropy"
10
license=('LicenseRef-Apple-Sample-Code')
11
depends=(
12
'python'
13
'python-packaging'
14
'python-pytorch'
15
'python-setuptools'
16
'python-triton'
17
)
18
makedepends=(
19
'git'
20
'python-build'
21
'python-installer'
22
'python-setuptools'
23
'python-setuptools-scm'
24
'python-wheel'
25
)
26
checkdepends=(
27
'python-pytest'
28
)
29
optdepends=(
30
'python-nvidia-ml-py: for GPU clock detection when nvidia-smi is unavailable'
31
'python-transformers: for Hugging Face Transformers monkey-patching'
32
)
33
_archive="ml-cross-entropy"
34
# Upstream cuts no tags; pin the commit whose cut_cross_entropy.__version__ == pkgver.
35
_commit=b7a02791b234e187b524fb1dba6a812d521b203a
36
source=(
37
"git+$url.git#commit=$_commit"
38
'cce-exact-cpu-test-skip.patch'
39
)
40
sha256sums=(
41
'SKIP'
42
'e2b118aff76eced3e32650c75e2fd38b36549c8527a523c434eae5d1b88c7400'
43
)
44
45
prepare() {
46
cd "$_archive"
47
# The parameter is named "cce_exact"; upstream's "cce" comparison can
48
# never match and runs Ampere-only kernels during its CPU test job.
49
patch -Np1 -i "$srcdir/cce-exact-cpu-test-skip.patch"
50
}
51
52
build() {
53
cd "$_archive"
54
python -m build --wheel --no-isolation
55
}
56
57
check() {
58
cd "$_archive"
59
# CUDA/Triton kernel cases carry their own upstream skip marker. The same
60
# complete suite also exercises CPU z-loss and distributed/FSDP utilities.
61
CUDA_VISIBLE_DEVICES='' PYTHONPATH="$PWD:$PYTHONPATH" pytest -ra
62
63
CUDA_VISIBLE_DEVICES='' PYTHONPATH="$PWD:$PYTHONPATH" python - <<'PY'
64
import torch
65
from cut_cross_entropy import linear_cross_entropy
66
67
torch.manual_seed(4)
68
embeddings = torch.randn(2, 3, 5, requires_grad=True)
69
classifier = torch.randn(7, 5, requires_grad=True)
70
targets = torch.tensor([[1, 2, 3], [3, 4, 5]])
71
actual = linear_cross_entropy(
72
embeddings, classifier, targets, impl="torch_compile"
73
)
74
expected = torch.nn.functional.cross_entropy(
75
(embeddings @ classifier.T).flatten(0, 1), targets.flatten()
76
)
77
torch.testing.assert_close(actual, expected, rtol=1e-4, atol=1e-5)
78
actual.backward()
79
assert embeddings.grad is not None and classifier.grad is not None
80
print("CPU linear cross-entropy workflow passed")
81
PY
82
}
83
84
package() {
85
cd "$_archive"
86
python -m installer --destdir="$pkgdir" dist/*.whl
87
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
88
}
89
Scan history
| Scanned at (UTC) | Severity | Rules |
|---|---|---|
| 2026-09-21 00:26:32 | Clean | 2 |
| 2026-09-20 23:33:19 | Low | 1 |