-
Notifications
You must be signed in to change notification settings - Fork 49
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] Add multiple dispatch #4
Conversation
e5fe20a
to
c9f9617
Compare
mmeval/core/dispatcher.py
Outdated
_singleton_patch() | ||
except Exception as e: | ||
logger.warning( | ||
f'Patch `plum.type.TypeMeta` with singleton failed, raise error: {e}.') |
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.
Why does it probably fail?
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.
In the case of failures due to plum version changes, we can still work.
062e847
to
e47d1de
Compare
e47d1de
to
e054de0
Compare
mmeval/core/dispatcher.py
Outdated
logger.warning( | ||
f'Patch plum Type with hash value cache failed, raise error: {e}.') |
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.
We should describe that the evaluation speed will slow down.
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.
Updated
dfe724a
to
6273386
Compare
fac72fc
to
49dca40
Compare
Motivation
Some mmeval metrics may have different calculation methods depending on the deep learning framework or numeric computing libraries used, such as PyTorch and NumPy.
In order to deal with the dispatch issue of different calculation methods, we adopt a dynamic multiple dispatch mechanism based on type hints.
A simple example of multiple dispatch based on type hints is as follows:
Modification
Currently, we employ plum (a multiple dispatch library) to implement multiple dispatch mechanism in mmeval.
In this module, we optimized the execution speed of plum through the following two tricks:
Benefiting from the tricks above, plum dispatch got twice faster as before. More detail can be found at: beartype/plum#53
Besides, we implement
MMEvalDispatcher
to extend plum dispatch for better support oftyping.ForwardRef
.BenchMark
1. MeanIoU with dispatch [1w samples, 512*512 size, num_classes 100]
Test code
2. Accuracy with dispatch [100w samples, num_classes 1000]
The plum
type_of
runs into performance issues with big nested parameters. We should avoid this situation or hacktype_of
to only inspect a subset of the nested parameters. See: beartype/plum#53ps. Using the tricks above, we speed up the accuracy with multiple dispatch from 8.0 s to 5.6 s.
Test code