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

don't automatically batch when getobs from an array of graphs #170

Closed
CarloLucibello opened this issue May 22, 2022 · 1 comment · Fixed by #183
Closed

don't automatically batch when getobs from an array of graphs #170

CarloLucibello opened this issue May 22, 2022 · 1 comment · Fixed by #183

Comments

@CarloLucibello
Copy link
Member

CarloLucibello commented May 22, 2022

We currently have the following definitions

# DataLoader compatibility passing a vector of graphs and
# effectively using `batch` as a collated function.
MLUtils.numobs(data::Vector{<:GNNGraph}) = length(data)
MLUtils.getobs(data::Vector{<:GNNGraph}, i::Int) = data[i]
MLUtils.getobs(data::Vector{<:GNNGraph}, i) = Flux.batch(data[i])

that make for a nice interaction with MLUtils.DataLoader since we have automatic batching a.k.a. collating.

On the other hand, this doesn't well play well with other transformations in MLUtils, where one ends up with a batched graph even if they didn't want to:

julia> using MLUtils, GraphNeuralNetworks

julia> graphs = [rand_graph(10, 20)  for i=1:5]
5-element Vector{GNNGraph{Tuple{Vector{Int64}, Vector{Int64}, Nothing}}}:
 GNNGraph(10, 20)
 GNNGraph(10, 20)
 GNNGraph(10, 20)
 GNNGraph(10, 20)
 GNNGraph(10, 20)

julia> shuffleobs(graphs) |> getobs
GNNGraph:
    num_nodes = 50
    num_edges = 100
    num_graphs = 5

We should remove the automatic batching from here, and the DataLoader itself should provide automatic batching by calling MLUtils.batch

@CarloLucibello
Copy link
Member Author

Let's wait for the outcome of the discussion in JuliaML/MLUtils.jl#90 and for whatever DataLoader Flux is exporting to have a collate option before solving this issue.

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 a pull request may close this issue.

1 participant