Conversation
| def set_smashed_working_model(self, working_model: Any) -> None: | ||
| """ | ||
| Set the smashed working model. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| working_model : Any | ||
| The smashed working model. | ||
| """ | ||
| self.smashed_working_model = working_model | ||
|
|
||
| def get_smashed(self) -> "ModelMixin": | ||
| """ | ||
| Get the smashed model. | ||
|
|
||
| Returns | ||
| ------- | ||
| ModelMixin | ||
| The smashed model. | ||
| """ | ||
| return self.smashed_pipeline |
There was a problem hiding this comment.
is there a reason for using this instead of mc.smashed_working_model = working_model and mc.smashed_pipeline from outside?
There was a problem hiding this comment.
This self.smashed_working_model = working_model was super cryptic to me, when i first read it before. So i add functions to name what is happening - so just readability
There was a problem hiding this comment.
I think in all cases the user needs to know what they are doing with the ModelContext, and these setter and getter are adding complexity... Using these variables could be explained within an error raised in the __exit__ if smashed_working_model wasn't set.
There was a problem hiding this comment.
i would rename the functions, as with the current names there is not really a difference to just assigning and reading.
i like having this abstraction however, without ever seeing the inside of this context it is hard to understand from the outside what is happening
gsprochette
left a comment
There was a problem hiding this comment.
Good job fixing this ! We're using a context in a weird way so we should spend a minute making it extra clear and extra clean, all my comments go in that direction :)
llcnt
left a comment
There was a problem hiding this comment.
Thanks again for the fix, it is much more clean :)
|
|
||
|
|
||
| class ModelContext: | ||
| class ModelContext(AbstractContextManager): |
There was a problem hiding this comment.
What does this AbstractContextManager provide us ? Any reason why we want our mc to depend on it? :)
There was a problem hiding this comment.
tbh nothing - just readability that this is a ContextManager - should i remove it?
…ate the working_model
…ead_only , and add read_only to the respective use-cases
…re architecture agnostic, also use them to remove duplicate access logic
gsprochette
left a comment
There was a problem hiding this comment.
That's almost ready to go, I left a couple of comments in the read_only check because it can still be improved. Once this is done, you can merge :)
| """ | ||
| if self.smashed_working_model is None: | ||
| return | ||
| if self.read_only: |
There was a problem hiding this comment.
We could also check if self.read_only and self.smashed_working_model is not None because this is bound to produce a cryptic bug
…ntext is wrongly used
Description
This PR refactors the ModelContext abstraction
Before the ModelContext used the incoming pipeline as a storage, for the smashed model, now the context itself is returned to get resources from.
Using pipeline as storage device, lead to problems when e.g. using the combination hqq+torch.compile
The changes include:
Related Issue
Type of Change
How Has This Been Tested?
Locally ran all tests for algorithms which use ModelContext
Checklist
Additional Notes
There might be a point of moving the ModelContext to the apply wrapper, to avoid duplicate code