-
Notifications
You must be signed in to change notification settings - Fork 324
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
Pruning: Keras subclassed model increased support #155
Comments
It seems to me we are mixing a few issues. I want to make sure I understand the problem correctly. Please correct me if I'm wrong. Issue is about handling models recursively - a Keras Model which contains another model, not about subclass models. If one of the layers in the model is So, if the user provides the the following. model1 = tf.keras.Sequential([tf.keras.layers.Dense(3)])
model2 = tf.keras.Sequential([model1, tf.keras.layers.Dense(2)]) we should prune both the Dense layers, and recursively traverse the model. I agree with that. I am not quite sure how the subclass models play a role here. It is possible a user combines a keras Since we can't reliably clone a subclass model, it isn't possible for us to apply pruning to the model. |
Hi @nutsiepully. I am currently having problems with pruning nested keras models. My model is based on the matterport's mask-rcnn repo. I have a model which contains an inner model which is called multiple times within the outer model but has shared weights. |
Hi @liyunlu0618 , can you check the current status? |
We recently added support for pruning nested models, see this PR. For subclass models, since keras doesn't support cloning, we still don't have a model-level API. You can still re-construct the model and wrapper the layers to prune with the pruning API. |
it seems subclass prune still not support in 0.7.1 |
Good day everyone :) I would also like to chip in to this discussion as I too have been struggling to get Nested Model Pruning to work correctly. I couldn't help noticing that support has been added but for some reason my implementation does not seem to work.
Observed behaviour:
It seems to me like the pruning is not even taking place. However, if I instantiate a model without nested models and run the exact same logic pipeline, then pruning acts exactly as expected and all layers are pruned successfully. Am I perhaps missing a step that is not mentioned in the documentation for tensorflow/keras model pruning? Any help would be greatly appreciated. Side notes:
|
@alanchiao Hi, recently I'm working on pruning subclass models and the model seems not able to converge with pruning. I tired to apply the prune_low_magnitude API directly on the layers to be pruned within the subclasses and the pruning schedule applied to each layer is the same. |
Currently the pruning API will throw an error when a subclassed model is passed to it. Users can get around this by diving into the subclassed models and applying pruning to individual Sequential/Functional models and tf.keras layers.
Better support is important for various cases (e.g. Object Detection, BERT examples) and issues such as this one.
We can provide better support for pruning an entire subclassed model.
model inside a subclassed model.
Implementation-wise, we can iterate through the layers of a subclassed model (and nested models) and applying pruning to all of them. Replacing a layer in an already created model will be tricky and we'd have to do this without clone_model.
The text was updated successfully, but these errors were encountered: