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

Add getmodel and setmodel from/to LogDensityFunction #626

Merged
merged 13 commits into from
Jul 22, 2024

Conversation

sunxd3
Copy link
Collaborator

@sunxd3 sunxd3 commented Jul 1, 2024

@sunxd3 sunxd3 changed the title Add setmodel and getmodel from/to LogDensityFunction Add getmodel and setmodel from/to LogDensityFunction Jul 1, 2024
sunxd3 and others added 4 commits July 1, 2024 14:13
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@@ -23,4 +25,17 @@ function LogDensityProblemsAD.ADgradient(
)
end

function DynamicPPL.setmodel(
f::LogDensityProblemsAD.ReverseDiffLogDensity{L,Nothing}, model::DynamicPPL.Model
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@torfjelde @yebai this will error because ReverseDiffLogDensity can't be found. It is defined under package extension(https://github.com/tpapp/LogDensityProblemsAD.jl/blob/449e5661bc2667f7bef061e148a6ea5526cbb427/ext/LogDensityProblemsADReverseDiffExt.jl#L25), do you know how to handle it here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't dispatch on types from package extensions. IIRC, that is a limitation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah this is annoying 😕

Don't really see how can avoid this tbh. One alternative is to just define our own AD log density model which contains the ADTypes.AbstractADType instead and uses DifferentiationInterface.jl or something. Or we raise an issue in LogDensityProblemsAD.jl to make the structs part of the main package instead of the extension to allow this stuff.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to move these structs into the main package.

@sunxd3
Copy link
Collaborator Author

sunxd3 commented Jul 16, 2024

@yebai @torfjelde I don't think we need this PR now. The motivation of this PR was that we want customized setmodel for different AD backend. We more or less established at TuringLang/Turing.jl#2231 (comment) that we will postpone this until we need it.

@yebai
Copy link
Member

yebai commented Jul 16, 2024

@sunxd3 let's still transfer these methods from Turing into DynamicPPL so we can maintain them from DynamicPPL.

sunxd3 and others added 6 commits July 16, 2024 17:37
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@coveralls
Copy link

coveralls commented Jul 17, 2024

Pull Request Test Coverage Report for Build 9992511738

Details

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • 24 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.03%) to 81.41%

Files with Coverage Reduction New Missed Lines %
src/model.jl 1 87.0%
src/simple_varinfo.jl 5 82.18%
src/varinfo.jl 6 84.85%
src/threadsafe.jl 12 46.73%
Totals Coverage Status
Change from base Build 9945722994: 0.03%
Covered Lines: 2807
Relevant Lines: 3448

💛 - Coveralls

@sunxd3 sunxd3 marked this pull request as ready for review July 18, 2024 08:26
Copy link
Member

@torfjelde torfjelde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM:)

Just bump patch version + remove unnecessary addition of HypothesisTests.jl to the test project?

@@ -1,6 +1,7 @@
[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8"
HypothesisTests = "09f84164-cd44-5f33-b23f-e6b0d136a0d5"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unintended?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But maybe better solution? 🤔

@sunxd3
Copy link
Collaborator Author

sunxd3 commented Jul 19, 2024

@torfjelde another look? 🙏

@torfjelde
Copy link
Member

LGTM:)

@sunxd3 sunxd3 enabled auto-merge July 22, 2024 07:23
@sunxd3 sunxd3 added this pull request to the merge queue Jul 22, 2024
Merged via the queue into master with commit 36008f9 Jul 22, 2024
11 of 12 checks passed
@sunxd3 sunxd3 deleted the sunxd/setmodel_and_getmodel branch July 22, 2024 09:46
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 this pull request may close these issues.

None yet

4 participants