mcabbott / mcabbott/AxisKeys.jl

unsupported keyword argument "time" when taking a gradient with Zygote

Open
#140 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
154
Forks
31
PR merge metrics
No merged PRs in 30d

Description

Doing the following outputs a reasonable error? Any hints? Doing a similar function without AxisKeys works, however the advantage of using the time dimension is lost, which I would like to keep.

I suppose that I will need a new rule, however not sure how to actually start doing it.

using AxisKeys
using AxisKeys: KeyedArray as KA
using Zygote

ab = (;
    a =KA([5.0f0, 10.0f0];  time=1:2),
    b = KA([-2.0f0, 0.1f0];  time=1:2),
    )

function getVals(ab::NamedTuple, ts::Int)
    map(ab) do v
        in(:time, AxisKeys.dimnames(v)) ? v[time=ts][1] : v
    end
end

gradient(x -> x^2 + x*sum(getVals(ab,2)), 5)
ERROR: MethodError: no method matching adjoint(::Zygote.Context{false}, ::typeof(getindex), ::KeyedArray{Float32, 1, NamedDimsArray{(:time,), Float32, 1, Vector{Float32}}, Base.RefValue{UnitRange{Int64}}}; time=2)
Closest candidates are:
  adjoint(::ZygoteRules.AContext, ::typeof(getindex), ::AbstractArray, ::Any...) at none:0 got unsupported keyword argument "time"
  adjoint(::ZygoteRules.AContext, ::Base.Fix2, ::Any) at none:0 got unsupported keyword argument "time"
  adjoint(::ZygoteRules.AContext, ::Base.Fix1, ::Any) at none:0 got unsupported keyword argument "time"
  ...
Stacktrace:
  [1] _pullback
    @ ~/.julia/packages/ZygoteRules/OgCVT/src/adjoint.jl:75 [inlined]
  [2] _pullback
.
.
.

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

No source file or test is named. Begin by running the provided Julia AxisKeys/Zygote reproduction, then trace the adjoint handling for keyword-based getindex with the time dimension. Done means the gradient example no longer raises the unsupported keyword argument error while retaining time-based indexing.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.