Skip to content

【KernelGen】Add fmod operator - #1737

Merged
bin913 merged 6 commits into
flagos-ai:masterfrom
Schopenhauer-loves-Hegel:auto-gen/fmod
May 11, 2026
Merged

【KernelGen】Add fmod operator#1737
bin913 merged 6 commits into
flagos-ai:masterfrom
Schopenhauer-loves-Hegel:auto-gen/fmod

Conversation

@Schopenhauer-loves-Hegel

Copy link
Copy Markdown
Collaborator

PR Category

Operator

Type of Change

New Feature

Description

Add fmod operator implementation with Triton kernel.

  • Implementation mode: pointwise_dynamic
  • Accuracy test: 90/90 passed

Issue

N/A

Progress

  • Change is properly reviewed (1 reviewer required, 2 recommended).
  • Change is responded to an issue.
  • Change is fully covered by a UT.

Performance

torch.bfloat16

Shape Torch Latency (ms) Gems Latency (ms) Speedup
[1073741824] 4.7215 4.7127 1.002
[64, 64] 0.0074 0.0079 0.939
[4096, 4096] 0.0871 0.0873 0.997
[64, 512, 512] 0.0879 0.0870 1.011
[1024, 1024, 1024] 4.7193 4.6852 1.007
[1024, 1] 0.0083 0.0074 1.130
[1024, 16] 0.0076 0.0076 1.000
[1024, 256] 0.0092 0.0095 0.963
[1024, 4096] 0.0296 0.0287 1.031
[1024, 65536] 0.3062 0.3044 1.006
[64, 64, 1] 0.0074 0.0080 0.932
[64, 64, 16] 0.0078 0.0078 1.000
[64, 64, 256] 0.0134 0.0140 0.961
[64, 64, 4096] 0.0870 0.0872 0.997
[64, 64, 65536] 1.1894 1.1779 1.010

torch.float16

Shape Torch Latency (ms) Gems Latency (ms) Speedup
[1073741824] 4.7231 4.7091 1.003
[64, 64] 0.0074 0.0084 0.885
[4096, 4096] 0.0870 0.0873 0.996
[64, 512, 512] 0.0874 0.0869 1.005
[1024, 1024, 1024] 4.7218 4.6844 1.008
[1024, 1] 0.0079 0.0083 0.946
[1024, 16] 0.0081 0.0086 0.944
[1024, 256] 0.0101 0.0100 1.006
[1024, 4096] 0.0296 0.0295 1.003
[1024, 65536] 0.3061 0.3043 1.006
[64, 64, 1] 0.0074 0.0074 0.996
[64, 64, 16] 0.0078 0.0086 0.907
[64, 64, 256] 0.0134 0.0139 0.963
[64, 64, 4096] 0.0870 0.0866 1.005
[64, 64, 65536] 1.1882 1.1823 1.005

torch.float32

Shape Torch Latency (ms) Gems Latency (ms) Speedup
[1073741824] 9.4564 9.3270 1.014
[64, 64] 0.0076 0.0076 0.996
[4096, 4096] 0.1586 0.1583 1.002
[64, 512, 512] 0.1583 0.1581 1.001
[1024, 1024, 1024] 9.4667 9.3252 1.015
[1024, 1] 0.0079 0.0080 0.988
[1024, 16] 0.0076 0.0085 0.888
[1024, 256] 0.0104 0.0112 0.926
[1024, 4096] 0.0480 0.0480 1.000
[1024, 65536] 0.6022 0.5980 1.007
[64, 64, 1] 0.0076 0.0076 1.000
[64, 64, 16] 0.0086 0.0085 1.007
[64, 64, 256] 0.0180 0.0173 1.043
[64, 64, 4096] 0.1591 0.1581 1.006
[64, 64, 65536] 2.3760 2.3485 1.012

Overall: median speedup = 1.002x, mean speedup = 0.990x (45 data points)


Generated by auto_gen tool with Claude Code

@Schopenhauer-loves-Hegel

Copy link
Copy Markdown
Collaborator Author

Closing in favor of grouped PRs to reduce review overhead.

@tengqm tengqm added tests and removed tests labels Mar 2, 2026
@Schopenhauer-loves-Hegel Schopenhauer-loves-Hegel changed the title Add fmod operator 【KernelGen】Add fmod operator Mar 23, 2026
@CLAassistant

CLAassistant commented Apr 15, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@factnn

factnn commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

fmod Benchmark Speedup Results

float16

Size Torch (ms) Gems (ms) Speedup
[1073741824] 4.739 4.880 0.971
[4096, 4096] 0.087 0.091 0.952
[1024, 1024, 1024] 4.739 4.889 0.969
[1024, 65536] 0.306 0.312 0.984
[64, 64, 65536] 1.195 1.206 0.991

float32

Size Torch (ms) Gems (ms) Speedup
[1073741824] 9.419 9.325 1.010
[4096, 4096] 0.160 0.159 1.004
[1024, 1024, 1024] 9.421 9.332 1.010
[1024, 65536] 0.600 0.599 1.001
[64, 64, 65536] 2.365 2.357 1.003

bfloat16

Size Torch (ms) Gems (ms) Speedup
[1073741824] 4.740 4.880 0.971
[4096, 4096] 0.087 0.090 0.961
[1024, 1024, 1024] 4.739 4.889 0.969
[1024, 65536] 0.306 0.312 0.982
[64, 64, 65536] 1.195 1.205 0.991

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Apr 18, 2026
@github-actions github-actions Bot removed the documentation Improvements or additions to documentation label Apr 18, 2026
@factnn
factnn force-pushed the auto-gen/fmod branch 3 times, most recently from d363c4a to 86b8686 Compare April 23, 2026 07:57
Comment thread benchmark/test_fmod_perf.py Outdated
Comment thread benchmark/test_fmod_perf.py Outdated
Comment thread src/flag_gems/ops/__init__.py Outdated
Comment thread src/flag_gems/__init__.py Outdated
Comment thread src/flag_gems/__init__.py Outdated
Comment thread benchmark/test_fmod_perf.py Outdated
Comment thread tests/test_fmod.py Outdated
Comment thread benchmark/test_fmod_perf.py Outdated
Comment thread benchmark/test_fmod_perf.py Outdated
Comment thread benchmark/test_fmod_perf.py Outdated
Comment thread benchmark/test_fmod_perf.py Outdated
Comment thread tests/test_fmod.py Outdated
Comment thread tests/test_fmod.py Outdated
Comment thread tests/test_fmod.py Outdated
Comment thread tests/test_fmod.py Outdated
Comment thread tests/test_fmod.py Outdated
Comment thread tests/test_fmod.py Outdated

@tengqm tengqm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall lgtm now. Thanks.

Comment thread src/flag_gems/ops/fmod.py Outdated
Comment thread src/flag_gems/ops/fmod.py Outdated
Comment thread src/flag_gems/ops/fmod.py Outdated
Comment thread src/flag_gems/ops/fmod.py Outdated
@factnn

factnn commented May 8, 2026

Copy link
Copy Markdown
Contributor

UT Results

Branch rebased to upstream/master and tests passed:

python -m pytest tests/ -m fmod --ref cpu -x -q
90 passed

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bin913 and others added 2 commits May 9, 2026 16:08
Co-authored-by: Qiming Teng <tengqm@outlook.com>
Signed-off-by: bin913 <842884726@qq.com>
Co-authored-by: Qiming Teng <tengqm@outlook.com>
Signed-off-by: bin913 <842884726@qq.com>
Comment thread benchmark/test_fmod.py Outdated
Comment thread benchmark/test_fmod.py Outdated
Comment thread benchmark/test_fmod.py Outdated
Comment thread benchmark/test_fmod.py Outdated
Comment thread benchmark/test_fmod.py Outdated
Comment thread benchmark/test_fmod.py Outdated
Comment thread benchmark/test_fmod.py Outdated
Comment thread benchmark/test_fmod.py Outdated
Comment thread tests/test_fmod.py Outdated
factnn and others added 3 commits May 9, 2026 16:38
Co-authored-by: Qiming Teng <tengqm@outlook.com>
Signed-off-by: Zang Peiyu <166481866+factnn@users.noreply.github.com>
Co-authored-by: Qiming Teng <tengqm@outlook.com>
Signed-off-by: bin913 <842884726@qq.com>
@bin913
bin913 merged commit 49654ef into flagos-ai:master May 11, 2026
32 of 33 checks passed
tengqm added a commit that referenced this pull request May 17, 2026
* feat: add fmod operator with tests and benchmark

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Apply suggestion from @tengqm

Co-authored-by: Qiming Teng <tengqm@outlook.com>
Signed-off-by: bin913 <842884726@qq.com>

* Apply suggestions from code review

Co-authored-by: Qiming Teng <tengqm@outlook.com>
Signed-off-by: bin913 <842884726@qq.com>

* Apply suggestions from code review

Co-authored-by: Qiming Teng <tengqm@outlook.com>
Signed-off-by: Zang Peiyu <166481866+factnn@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Qiming Teng <tengqm@outlook.com>
Signed-off-by: bin913 <842884726@qq.com>

---------

Signed-off-by: bin913 <842884726@qq.com>
Signed-off-by: Zang Peiyu <166481866+factnn@users.noreply.github.com>
Co-authored-by: factnn <1050552884@qq.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: bin913 <842884726@qq.com>
Co-authored-by: Qiming Teng <tengqm@outlook.com>
Co-authored-by: Zang Peiyu <166481866+factnn@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants