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

Use better colorings #246

Open
gdalle opened this issue Jun 12, 2024 · 6 comments
Open

Use better colorings #246

gdalle opened this issue Jun 12, 2024 · 6 comments

Comments

@gdalle
Copy link
Collaborator

gdalle commented Jun 12, 2024

As of #244, column coloring is used everywhere, for Jacobians and Hessians alike. However:

  • For Jacobians, row coloring + reverse mode may be faster than column coloring + forward mode, depending on the input and output dimensions
  • For Hessians, star coloring can leverage the symmetry of the matrix to use fewer colors, but it requires a more clever decompression algorithm

SparseMatrixColorings.jl also provides decompression utilities, which you may want to use for column and star coloring instead of recoding them.

Of course my recommendation is to use DifferentiationInterface.jl and stop worrying about all of that

@gdalle
Copy link
Collaborator Author

gdalle commented Jun 14, 2024

Apparently the lines to modify are

for j = 1:nvar
if b.colors[j] == icol
for k = b.colptr[j]:(b.colptr[j + 1] - 1)
i = b.rowval[k]
vals[k] = b.res[i]
end
end
end
end

I can cook up a PR this weekend

@amontoison
Copy link
Member

It will be fantastic Guillaume!

@gdalle
Copy link
Collaborator Author

gdalle commented Jun 17, 2024

I have taken a look and it's not possible with the current state of the code, because you interleave differentiation and decompression: evaluate the matrix-vector product for one color, dispatch into the relevant columns, rinse and repeat.
Meanwhile, SparseMatrixColorings.jl allows a complete separation of these two aspects. But that means you need to allow a larger buffer for the differentiation, of size (rows, column_colors) or (row_colors, columns).
As an example, here's how it's done in DI:
https://github.com/gdalle/DifferentiationInterface.jl/blob/b41db2ff5791d53e669e641a823effa957c42ff6/DifferentiationInterface/src/sparse/jacobian.jl#L75-L105

@amontoison
Copy link
Member

Should we start to switch to DI.jl?

@gdalle
Copy link
Collaborator Author

gdalle commented Jun 17, 2024

Do you have benchmarks to monitor possible performance regressions? I can't guarantee that DI will be everywhere as good as hand-tuned code that works for a specific backend

@tmigot
Copy link
Member

tmigot commented Jun 17, 2024

Agree with @gdalle , we should move forward on the benchmarking side. #248 is for the gradient, but then no difficult to extend the benchmark to more.

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

No branches or pull requests

3 participants