Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ on:
tags: [v*]
pull_request:

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
Expand All @@ -13,15 +24,15 @@ jobs:
fail-fast: false
matrix:
version:
- "1.6" # LTS
- "lts" # LTS
- "1" # Latest Release
os:
- ubuntu-latest
arch:
- x86
- x64
exclude:
- version: "1.6"
- version: "lts"
arch: x86
steps:
- uses: actions/checkout@v6
Expand All @@ -32,23 +43,9 @@ jobs:
- uses: julia-actions/cache@v3
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
# - uses: julia-actions/julia-processcoverage@v1
# - uses: codecov/codecov-action@v1
# with:
# file: lcov.info
# - uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# flag-name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
# parallel: true
# path-to-lcov: lcov.info
#
# finish:
# name: Coveralls Finished
# needs: test
# runs-on: ubuntu-latest
# steps:
# - uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# parallel-finished: true
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v7
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
19 changes: 0 additions & 19 deletions .github/workflows/Cancel.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/IntegrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ on:
tags: [v*]
pull_request:

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
test:
name: ${{ matrix.package.repo }}
Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/JuliaNightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ on:
schedule:
- cron: "0 0 * * *"

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read

jobs:
test:
name: ${{ matrix.os }} - ${{ matrix.arch }}
Expand All @@ -32,19 +43,8 @@ jobs:
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
parallel: true
path-to-lcov: lcov.info

finish:
name: Coveralls Finished
needs: test
runs-on: ubuntu-latest
steps:
- uses: coverallsapp/github-action@master
- uses: codecov/codecov-action@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
12 changes: 5 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRules"
uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2"
version = "1.73.1"
version = "1.74.0"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand All @@ -16,7 +16,6 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SparseInverseSubset = "dc90abb0-5640-4711-901d-7e5b23a2fada"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"

[compat]
Adapt = "3.4.0, 4"
Expand All @@ -28,26 +27,25 @@ FiniteDifferences = "0.12.20"
GPUArraysCore = "0.1.0, 0.2"
IrrationalConstants = "0.1.1, 0.2"
JLArrays = "0.1, 0.4"
JuliaInterpreter = "0.9, 0.12"
LinearAlgebra = "1"
ParallelTestRunner = "2"
Random = "1"
RealDot = "0.1"
SparseArrays = "1"
SparseInverseSubset = "0.1"
StaticArrays = "1.2"
Statistics = "1"
StructArrays = "0.6.11, 0.7"
SuiteSparse = "1"
julia = "1.6"
julia = "1.10"

[extras]
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["ChainRulesTestUtils", "FiniteDifferences", "JLArrays", "JuliaInterpreter", "Random", "StaticArrays", "Test"]
test = ["ChainRulesTestUtils", "FiniteDifferences", "JLArrays", "ParallelTestRunner", "Random", "StaticArrays", "Test"]
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

# ChainRules

[![CI](https://github.com/JuliaDiff/ChainRules.jl/workflows/CI/badge.svg?branch=master)](https://github.com/JuliaDiff/ChainRules.jl/actions?query=workflow%3ACI)
[![Travis](https://travis-ci.org/JuliaDiff/ChainRules.jl.svg?branch=master)](https://travis-ci.org/JuliaDiff/ChainRules.jl)
[![Coveralls](https://coveralls.io/repos/github/JuliaDiff/ChainRules.jl/badge.svg?branch=master)](https://coveralls.io/github/JuliaDiff/ChainRules.jl?branch=master)
[![CI](https://github.com/JuliaDiff/ChainRules.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/JuliaDiff/ChainRules.jl/actions/workflows/CI.yml?query=branch%3Amain)
[![Coverage](https://codecov.io/gh/JuliaDiff/ChainRules.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/JuliaDiff/ChainRules.jl)
[![PkgEval](https://juliaci.github.io/NanosoldierReports/pkgeval_badges/C/ChainRules.svg)](https://juliaci.github.io/NanosoldierReports/pkgeval_badges/report.html)
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
Expand Down
140 changes: 64 additions & 76 deletions src/rulesets/Base/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,73 +138,67 @@ end
##### fused 3-argument *
#####

if VERSION > v"1.7.0-"
using LinearAlgebra: mat_mat_scalar, mat_vec_scalar, StridedMaybeAdjOrTransMat

@eval using LinearAlgebra: mat_mat_scalar, mat_vec_scalar, StridedMaybeAdjOrTransMat

function rrule(
::typeof(mat_mat_scalar),
A::StridedMaybeAdjOrTransMat{<:CommutativeMulNumber},
B::StridedMaybeAdjOrTransMat{<:CommutativeMulNumber},
γ::CommutativeMulNumber
)
project_A = ProjectTo(A)
project_B = ProjectTo(B)
project_γ = ProjectTo(γ)
C = mat_mat_scalar(A, B, γ)
function mat_mat_scalar_back(Ȳraw)
Ȳ = unthunk(Ȳraw)
Athunk = InplaceableThunk(
dA -> mul!(dA, Ȳ, B', conj(γ), true),
@thunk(project_A(mat_mat_scalar(Ȳ, B', conj(γ)))),
)
Bthunk = InplaceableThunk(
dB -> mul!(dB, A', Ȳ, conj(γ), true),
@thunk(project_B(mat_mat_scalar(A', Ȳ, conj(γ)))),
)
γthunk = @thunk if iszero(γ)
# Could save A*B on the forward pass, but it's messy.
# This ought to be rare, should guarantee the same type:
project_γ(dot(mat_mat_scalar(A, B, oneunit(γ)), Ȳ) / one(γ))
else
project_γ(dot(C, Ȳ) / conj(γ))
end
return (NoTangent(), Athunk, Bthunk, γthunk)
function rrule(
::typeof(mat_mat_scalar),
A::StridedMaybeAdjOrTransMat{<:CommutativeMulNumber},
B::StridedMaybeAdjOrTransMat{<:CommutativeMulNumber},
γ::CommutativeMulNumber,
)
project_A = ProjectTo(A)
project_B = ProjectTo(B)
project_γ = ProjectTo(γ)
C = mat_mat_scalar(A, B, γ)
function mat_mat_scalar_back(Ȳraw)
Ȳ = unthunk(Ȳraw)
Athunk = InplaceableThunk(
dA -> mul!(dA, Ȳ, B', conj(γ), true),
@thunk(project_A(mat_mat_scalar(Ȳ, B', conj(γ)))),
)
Bthunk = InplaceableThunk(
dB -> mul!(dB, A', Ȳ, conj(γ), true),
@thunk(project_B(mat_mat_scalar(A', Ȳ, conj(γ)))),
)
γthunk = @thunk if iszero(γ)
# Could save A*B on the forward pass, but it's messy.
# This ought to be rare, should guarantee the same type:
project_γ(dot(mat_mat_scalar(A, B, oneunit(γ)), Ȳ) / one(γ))
else
project_γ(dot(C, Ȳ) / conj(γ))
end
return C, mat_mat_scalar_back
return (NoTangent(), Athunk, Bthunk, γthunk)
end
return C, mat_mat_scalar_back
end

function rrule(
::typeof(mat_vec_scalar),
A::StridedMaybeAdjOrTransMat{<:CommutativeMulNumber},
b::StridedVector{<:CommutativeMulNumber},
γ::CommutativeMulNumber
)
project_A = ProjectTo(A)
project_b = ProjectTo(b)
project_γ = ProjectTo(γ)
y = mat_vec_scalar(A, b, γ)
function mat_vec_scalar_back(dy_raw)
dy = unthunk(dy_raw)
Athunk = InplaceableThunk(
dA -> mul!(dA, dy, b', conj(γ), true),
@thunk(project_A(*(dy, b', conj(γ)))),
)
Bthunk = InplaceableThunk(
db -> mul!(db, A', dy, conj(γ), true),
@thunk(project_b(*(A', dy, conj(γ)))),
)
γthunk = @thunk if iszero(γ)
project_γ(dot(mat_vec_scalar(A, b, oneunit(γ)), dy))
else
project_γ(dot(y, dy) / conj(γ))
end
return (NoTangent(), Athunk, Bthunk, γthunk)
function rrule(
::typeof(mat_vec_scalar),
A::StridedMaybeAdjOrTransMat{<:CommutativeMulNumber},
b::StridedVector{<:CommutativeMulNumber},
γ::CommutativeMulNumber,
)
project_A = ProjectTo(A)
project_b = ProjectTo(b)
project_γ = ProjectTo(γ)
y = mat_vec_scalar(A, b, γ)
function mat_vec_scalar_back(dy_raw)
dy = unthunk(dy_raw)
Athunk = InplaceableThunk(
dA -> mul!(dA, dy, b', conj(γ), true), @thunk(project_A(*(dy, b', conj(γ))))
)
Bthunk = InplaceableThunk(
db -> mul!(db, A', dy, conj(γ), true), @thunk(project_b(*(A', dy, conj(γ))))
)
γthunk = @thunk if iszero(γ)
project_γ(dot(mat_vec_scalar(A, b, oneunit(γ)), dy))
else
project_γ(dot(y, dy) / conj(γ))
end
return y, mat_vec_scalar_back
return (NoTangent(), Athunk, Bthunk, γthunk)
end

end # VERSION
return y, mat_vec_scalar_back
end

#####
##### `muladd`
Expand Down Expand Up @@ -353,29 +347,23 @@ function rrule(::typeof(\), A::AbstractVecOrMat{<:Real}, B::AbstractVecOrMat{<:R
Ȳ = unthunk(ȳ)

Ȳf = Ȳ
@static if VERSION >= v"1.9"
# Need to ensure Ȳ is an array since since https://github.com/JuliaLang/julia/pull/44358
if !isa(Ȳ, AbstractArray)
Ȳf = [Ȳ]
end
# Need to ensure Ȳ is an array since since https://github.com/JuliaLang/julia/pull/44358
if !isa(Ȳ, AbstractArray)
Ȳf = [Ȳ]
end
Yf = Y
@static if VERSION >= v"1.9"
# Need to ensure Yf is an array since since https://github.com/JuliaLang/julia/pull/44358
if !isa(Y, AbstractArray)
Yf = [Y]
end
# Need to ensure Yf is an array since since https://github.com/JuliaLang/julia/pull/44358
if !isa(Y, AbstractArray)
Yf = [Y]
end
#@info "vars" typeof(Ȳ) typeof(Y) typeof(Yf) typeof(A) typeof(B)
∂A = @thunk begin
B̄ = A' \ Ȳf
Ā = -B̄ * Y'
t = (B - A * Y) * B̄'
@static if VERSION >= v"1.9"
# Need to ensure t is an array since since https://github.com/JuliaLang/julia/pull/44358
if !isa(t, AbstractArray)
t = [t]
end
# Need to ensure t is an array since since https://github.com/JuliaLang/julia/pull/44358
if !isa(t, AbstractArray)
t = [t]
end
Ā = add!!(Ā, t / A')
Ā = add!!(Ā, A' \ Yf * (Ȳ' - B̄'A))
Expand Down
4 changes: 0 additions & 4 deletions src/rulesets/Base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,6 @@ function rrule(config::RuleConfig{>:HasReverseMode}, ::typeof(map), f::F, xs::Tu
y = map(first, hobbits)
num_xs = Val(length(xs))
paddings = map(x -> ntuple(Returns(NoTangent()), (length(x) - length_y)), xs)
@static if VERSION < v"1.10.0-DEV.1194"
all(isempty, paddings) || @error """map(f, xs::Tuple...) does not allow mismatched lengths in Julia <1.10!
But its `rrule` does."""
end
function map_pullback(dy_raw)
dy = unthunk(dy_raw)
# We want to call the pullbacks in `rrule_via_ad` in reverse sequence to the forward pass:
Expand Down
14 changes: 1 addition & 13 deletions src/rulesets/Base/nondiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,7 @@
@non_differentiable readuntil(::IO, ::AbstractChar)
@non_differentiable readuntil(::IO, ::AbstractString)
@non_differentiable realpath(::AbstractString)
if isdefined(Base, :redirect_stdio)
@non_differentiable Base.redirect_stdio(::Any)
else
@non_differentiable redirect_stderr(
::Union{IOStream, Base.LibuvStream, Base.DevNull, IOContext},
)
@non_differentiable redirect_stdin(
::Union{IOStream, Base.LibuvStream, Base.DevNull, IOContext},
)
@non_differentiable redirect_stdout(
::Union{IOStream, Base.LibuvStream, Base.DevNull, IOContext},
)
end
@non_differentiable Base.redirect_stdio(::Any)
@non_differentiable relpath(::AbstractString, ::AbstractString)
@non_differentiable relpath(::String)
@non_differentiable repr(::Any)
Expand Down
Loading
Loading