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

Feat (inference_mode): pickle compatibility #1096

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Giuseppe5
Copy link
Collaborator

@Giuseppe5 Giuseppe5 commented Nov 18, 2024

Reason for this PR

Injector are not compatible with pickle when trying to do 'torch.save'.

In theory, once dependency injection is resolved, we don't need injectors anymore. We rely on the injector too much so this might break at times.

In quant_inference_mode, we detach the injector and save it so that we can re-attach it at the exit of the context manager.

Example usage:

import brevitas.nn as qnn

model =  qnn.QuantLinear(3, 8)
with quant_inference_mode(model , delete_injector=True):
    b = model(torch.randn(1,3))
    torch.save(model , 'test.pickle')

Changes Made in this PR

Remove/Reattach quant injector when needed.

Testing Summary

None, Draft PR.

Risk Highlight

  • This PR includes code from another work (please detail).
  • This PR contains API-breaking changes.
  • This PR depends on work in another PR (please provide links/details).
  • This PR introduces new dependencies (please detail).
  • There are coverage gaps not covered by tests.
  • Documentation updates required in subsequent PR.

Potential edge cases not tested

Checklist

  • Code comments added to any hard-to-understand areas, if applicable.
  • Changes generate no new warnings.
  • Updated any relevant tests, if applicable.
  • No conflicts with destination dev branch.
  • I reviewed my own code changes.
  • Initial CI/CD passing.
  • 1+ reviews given, and any review issues addressed and approved.
  • Post-review full CI/CD passing.

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.

1 participant