`pick_batchsize` spends ~1 µs constructing `BatchSizeSettings{B}(N)` with a run-time `B`
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- julia
- Domain
- performance
Research direction
Read pick_batchsize(::AutoForwardDiff{nothing}, N) and pick_batchsize(::AutoEnzyme, N) in DifferentiationInterface, then run the supplied benchmark on Julia 1.12.7. Compare the batch-size settings and timings against the concrete-type example; done looks like equivalent settings with lower overhead for batch-size selection and the reported sparse-Jacobian operations.
Written by the indexing model from the issue text.
Description
pick_batchsize(::AutoForwardDiff{nothing}, N) and pick_batchsize(::AutoEnzyme, N) call BatchSizeSettings{B}(N) with a B that is only known at run time. On Julia 1.12.7 with DI 0.7.17 this takes about 1.1 µs. Computing all type parameters first and calling the concrete type gives the same value in about 0.13 µs:
using DifferentiationInterface, ForwardDiff, Chairmarks
const DI = DifferentiationInterface
partial(B, N) = DI.BatchSizeSettings{B}(N)
function concrete(B, N)
singlebatch = B == N
aligned = (B == N == 0) || (N % B == 0)
return DI.BatchSizeSettings{B, singlebatch, aligned}(N)
end
@assert partial(1, 1) === concrete(1, 1) && partial(8, 13) === concrete(8, 13)
@be 1 DI.pick_batchsize(AutoForwardDiff(), _) # 1145 ns, 6 allocs
@be 1 DI.pick_batchsize(AutoForwardDiff(; chunksize = 1), _) # 746 ns, 2 allocs
@be 1 partial(_, _) # 1138 ns, 6 allocs
@be 1 concrete(_, _) # 128 ns, 1 alloc
This dominates unprepared sparse Jacobians of cheap functions. For f!(y, x) = (y .= 2 .* x) with n = 8, a known diagonal pattern and GreedyColoringAlgorithm(), using concrete in pick_batchsize(::AutoForwardDiff{nothing}, N) takes jacobian!(f!, y, J, backend, x) from 1.88 µs to 0.72 µs and prepare_jacobian from 1.71 µs to 0.56 µs.
- Dominant language
- Julia
- Stars
- 314
- Forks
- 36
- Avg merge
- 2h 14m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaDiff/DifferentiationInterface.jl
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JuliaDiff/DifferentiationInterface.jl#1069 · 1 comment ·
-
bot
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JuliaDiff/DifferentiationInterface.jl#1011 · 3 comments ·
-
AutoEnzyme Jacobian preparation scalar-indexes Reactant traced arraysMay be free again A pull request for this issue was closed without being merged. Openbackend wontfix
Difficulty 4/5 3-5 days Newbie friendliness 52/100
JuliaDiff/DifferentiationInterface.jl#1066 · 10 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
All issues in JuliaDiff/DifferentiationInterface.jl
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
SciML/DiffEqNoiseProcess.jl#342 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
oxfordcontrol/COSMO.jl#211 ·
-
documentation
Difficulty 2/5 Half a day Newbie friendliness 65/100
Maintainers usually reply within 6 days