Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for clamp and clamp! #247

Merged
merged 5 commits into from
Nov 8, 2024
Merged

feat: add support for clamp and clamp! #247

merged 5 commits into from
Nov 8, 2024

Conversation

avik-pal
Copy link
Collaborator

@avik-pal avik-pal commented Nov 8, 2024

  • needs testing

src/TracedRArray.jl Outdated Show resolved Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@@ -270,6 +270,17 @@ Base.abs2(x::TracedRNumber{<:Real}) = x^2

Base.log1p(x::TracedRNumber{T}) where {T} = log(x + one(T))

function Base.clamp(x::TracedRNumber{T}, min::Number, max::Number) where {T}
Copy link
Member

Choose a reason for hiding this comment

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

do we want to have versions where min and/or max are tracedvalues?

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Reactant.jl Benchmarks

Benchmark suite Current: f652d5d Previous: f34ec8f Ratio
ViT base (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :after_enzyme) 6961960600 ns 7027955167 ns 0.99
ViT base (256 x 256 x 3 x 32)/forward/CPU/Reactant 5008876591 ns 5911790203 ns 0.85
ViT base (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :before_enzyme) 5099056791 ns 5039003346 ns 1.01
ViT base (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :only_enzyme) 7634865394 ns 7620308614 ns 1.00
ViT base (256 x 256 x 3 x 32)/forward/CPU/Lux 35163148305 ns 31357074001 ns 1.12
ViT small (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :after_enzyme) 1573585661 ns 1572787384 ns 1.00
ViT small (256 x 256 x 3 x 4)/forward/CPU/Reactant 1548430614 ns 1548995246 ns 1.00
ViT small (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :before_enzyme) 1544114996 ns 1555509740 ns 0.99
ViT small (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :only_enzyme) 3302096089 ns 3467552492 ns 0.95
ViT small (256 x 256 x 3 x 4)/forward/CPU/Lux 3626707137 ns 3419731143 ns 1.06
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :after_enzyme) 2132195996 ns 2180418814 ns 0.98
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Reactant 2130406024 ns 2173460673 ns 0.98
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :before_enzyme) 2124925292 ns 2158353524 ns 0.98
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :only_enzyme) 3894240054 ns 3927830322 ns 0.99
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Lux 6049924945 ns 6253378741.5 ns 0.97
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :after_enzyme) 1423316093 ns 1440134479 ns 0.99
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Reactant 1422220966 ns 1421557207 ns 1.00
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :before_enzyme) 1411767213 ns 1428360591 ns 0.99
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :only_enzyme) 3159441173 ns 3208488833 ns 0.98
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Lux 1307717501 ns 1139085595.5 ns 1.15
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :after_enzyme) 1707093674 ns 1712651271 ns 1.00
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Reactant 1709893988 ns 1706763760 ns 1.00
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :before_enzyme) 1696454194 ns 1704312368 ns 1.00
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :only_enzyme) 3443868848 ns 3479746822 ns 0.99
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Lux 2887267582 ns 3154626911 ns 0.92
ViT small (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :after_enzyme) 2187516129 ns 2175602283 ns 1.01
ViT small (256 x 256 x 3 x 16)/forward/CPU/Reactant 2203005347 ns 2162683110 ns 1.02
ViT small (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :before_enzyme) 2186065337 ns 2187544254 ns 1.00
ViT small (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :only_enzyme) 3914533482 ns 3928792736 ns 1.00
ViT small (256 x 256 x 3 x 16)/forward/CPU/Lux 5664834406 ns 6172504320 ns 0.92
ViT small (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :after_enzyme) 2943345673 ns 2997646442 ns 0.98
ViT small (256 x 256 x 3 x 32)/forward/CPU/Reactant 2965291585 ns 2957532725 ns 1.00
ViT small (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :before_enzyme) 3017015460 ns 2960803098 ns 1.02
ViT small (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :only_enzyme) 4820077455 ns 4863944327 ns 0.99
ViT small (256 x 256 x 3 x 32)/forward/CPU/Lux 13103708690 ns 22191688400 ns 0.59
ViT base (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :after_enzyme) 3153534399 ns 3157390991 ns 1.00
ViT base (256 x 256 x 3 x 16)/forward/CPU/Reactant 3171484785 ns 3212937029 ns 0.99
ViT base (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :before_enzyme) 3168248608 ns 3419812778 ns 0.93
ViT base (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :only_enzyme) 5052248374 ns 5010112071 ns 1.01
ViT base (256 x 256 x 3 x 16)/forward/CPU/Lux 14025077866 ns 10940648930 ns 1.28
ViT base (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :after_enzyme) 2065027295 ns 1843742771 ns 1.12
ViT base (256 x 256 x 3 x 4)/forward/CPU/Reactant 1898465030 ns 1827524417 ns 1.04
ViT base (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :before_enzyme) 1883176767 ns 1842645194 ns 1.02
ViT base (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :only_enzyme) 3720749988 ns 3593953850 ns 1.04
ViT base (256 x 256 x 3 x 4)/forward/CPU/Lux 3362179008 ns 3544018917 ns 0.95

This comment was automatically generated by workflow using github-action-benchmark.

@avik-pal avik-pal marked this pull request as ready for review November 8, 2024 15:48
@avik-pal avik-pal requested a review from wsmoses November 8, 2024 15:48
@avik-pal avik-pal merged commit 3ba7c3e into main Nov 8, 2024
20 of 30 checks passed
@avik-pal avik-pal deleted the ap/clamp branch November 8, 2024 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants