mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-08-02 00:01:52 +00:00
* [fx] metainfo class for auto parallel * [fx] add unit test for linear metainfo * [fx] fix bwd param for linear * [fx] modify unit test * [fx] modify unit test * [fx] modify import * [fx] modify import * [fx] modify import * [fx] move meta profiler to auto parallel
33 lines
763 B
Python
33 lines
763 B
Python
__all__ = ['Registry']
|
|
|
|
|
|
class Registry:
|
|
|
|
def __init__(self, name):
|
|
self.name = name
|
|
self.store = {}
|
|
|
|
def register(self, source):
|
|
|
|
def wrapper(func):
|
|
if isinstance(source, (list, tuple)):
|
|
# support register a list of items for this func
|
|
for element in source:
|
|
self.store[element] = func
|
|
else:
|
|
self.store[source] = func
|
|
return func
|
|
|
|
return wrapper
|
|
|
|
def get(self, source):
|
|
assert source in self.store, f'{source} not found in the {self.name} registry'
|
|
target = self.store[source]
|
|
return target
|
|
|
|
def has(self, source):
|
|
return source in self.store
|
|
|
|
|
|
meta_register = Registry('meta')
|