-
Notifications
You must be signed in to change notification settings - Fork 180
JP-3930: Step function for opening models #9723
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
Conversation
|
Initial regtests here: Comparing to regtests for #9709, performance is restored to what it was before the change in all cases. |
|
@emolter @braingram @tapastro @penaguerrero - I'd like your thoughts on this proposed change to Step.open_model, when you have a chance. I'll leave it at draft for now. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9723 +/- ##
==========================================
+ Coverage 83.38% 83.43% +0.05%
==========================================
Files 366 366
Lines 37770 37784 +14
==========================================
+ Hits 31493 31525 +32
+ Misses 6277 6259 -18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for continuing to work on this Melanie! Overall I think something like this would be very beneficial. To re-state what I view as the design requirements,
I think your proposal achieves all of these, but I'm still trying to work through when/if closing needs to happen. My expectations would be as follows: my expectation would be that now I expect I would expect that the individual Steps within the pipeline will keep the model open when passed between them, to avoid having to close and re-open it. Finally, if I call the pipeline from the command-line, I'd expect Can you say a bit more about how this works? |
|
Thanks for taking a look, Ned. I agree with all your requirements and expectations, except I might restate # 3 as: The way I would envision this working in the future is:
|
|
Thanks for this work, Melanie! I think the code you propose is a good generalization for both steps that take regular models as well as steps that take a model container or library as input, and I agree that it is better to decide to make this copy or not at a higher level than the step. This should improve the memory footprint overall in all pipelines! When I did the test for run for Detector1 in #8588 (comment), the memory footprint in my laptop for that heavy 2.6 GB uncal MIRI file went down from about 60 GB to about 40 GB. I am curious to see the changes with your proposal. |
braingram
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together. I left some inline comments and overall the approach looks good to me.
ec06155 to
82e1d45
Compare
|
It sounds like everyone so far generally likes this approach, so I will work on adding some more tests to verify the Edit: tests added in bcd0064 |
|
I remembered that when I worked on this for all the steps of detector 1, I made a copy when necessary and then immediately deleted the original object. This reduced memory quite a bit. |
I think that won't work in general, because it would violate the user assumption that if they provide a datamodel to the step, it will still exist after the step completes. I'm hoping, though, that we can get similar savings by not making copies when it's not needed. We'll also definitely need to give some thought to places where we can usefully delete objects after they're no longer needed, especially within the pipelines, which often have more knowledge about which objects are needed than the steps do. |
4f19309 to
bfff125
Compare
c22e031 to
56bd36c
Compare
|
@tapastro - I'm taking this PR out of draft because it would be nice to get into this build if possible. It restores performance to previous benchmarks for some stage 3 use cases. |
|
The new test Would it be helpful for me to re-review this? |
Yes please! It's been a minute, so would be very helpful to have you recheck it. I'll rerun the regtests. Edit for regtest results: test_ngroup_1 is passing, but there are unrelated failures from a MIRI CRDS delivery. I'll run again when those are okified. Edit again: all passing now. |
emolter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the detailed test suite! This looks good to me - regtests for memory usage were helpful to determine that this is doing what we expect.
4042a65 to
ad36c6c
Compare
Partially resolves JP-3930
Continuing work on making sure input models are not modified by Steps and following up on #9709, which introduced some new data copies for some outlier_detection use cases.
For outlier_detection, I added an internal function that decided from the input whether a copy was needed, and returned an open model. I realized something similar was needed for skymatch and tweakreg, so I'm proposing here to add a Step.prepare_output function to more generally support this use case, and expand its use to the other image3 steps that expect ModelLibrary input.
This is drawing on @braingram's suggestion here: #8588 (comment)
Unlike the proposed function in that PR, though, this one would explicitly support the expectation that input models are not modified after they are provided to a step or pipeline. Also unlike that function, this is not meant to be used as
with self.open_model(input_data) as model:at the top of every step, because it will vary by use case whether the open model should be closed within the step.Since the Step function can check whether it is part of a pipeline, I added one extra clause to the implementation from the OutlierDetectionStep: if self.parent is not None, copies are not made. This ends up gaining back the memory costs introduced in #9709.
I think we could potentially expand the use of this function to the remaining Steps, and use it to be more intentional about when we copy input data and when we close the input models. If we don't make shallow copies with
with datamodels.open(model), and we do make deep copies when needed, then the only time the opened model should need to be closed within a step is if the output is a completely new model generated within the step (not a modified version of the input model).See also the discussion here: spacetelescope/stdatamodels#512
Tasks
Build 12.0(use the latest build if not sure)no-changelog-entry-needed)changes/:echo "changed something" > changes/<PR#>.<changetype>.rst(see changelog readme for instructions)docs/pageokify_regteststo update the truth files