JuliaDiff / JuliaDiff/ChainRules.jl

`@fastmath maximum` broken on 1.10

Open
#690 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

missing rule
Dominant language
Julia
Stars
475
Forks
98
PR merge metrics
No merged PRs in 30d

Description

julia> using Zygote, BenchmarkTools

julia> @macroexpand1 @fastmath maximum(x)  # this is new
:(Base.FastMath.maximum_fast(x))

julia> VERSION
v"1.10.0-DEV.421"

julia> gradient(x -> sum(maximum(x; dims=1)), [1,3,2])
([0.0, 1.0, 0.0],)

julia> @fastmath gradient(x -> sum(maximum(x; dims=1)), [1,3,2])
ERROR: Mutating arrays is not supported -- called setindex!(Vector{Int64}, ...)

julia> @btime gradient(x -> maximum(x), $([1,3,2]))
  min 1.113 μs, mean 1.214 μs (15 allocations, 528 bytes)
([0.0, 1.0, 0.0],)

julia> @btime @fastmath gradient(x -> maximum(x), $([1,3,2]))  # also misses the rule
  min 28.541 μs, mean 29.743 μs (159 allocations, 5.94 KiB)
([0.0, 1.0, 0.0],)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the shown Julia commands involving Zygote, @fastmath, and maximum, then trace the handling of Base.FastMath.maximum_fast and the gradient rule. Done means @fastmath gradient calls match ordinary maximum gradients without the mutation error or missed rule.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.