-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User-defined data type and rank constraints (#72)
* feat: support rank and dtype constrol * feat+fix: patch requires * fix(try): use MANIFEST.in to robustify package data * feat: impl include and exclude by op.name() * feat: patch extra requires via cli * refact: test mgen.patch_requires and allow it be list or single * fix: check ListConfig
- Loading branch information
Showing
15 changed files
with
215 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# include yaml files under nnsmith/config/**/*.yaml | ||
include nnsmith/config/**/*.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,29 @@ | ||
import functools | ||
import types | ||
from typing import List | ||
from typing import List, Optional, Type | ||
|
||
from nnsmith.abstract.op import AbsOpBase | ||
from nnsmith.abstract.tensor import AbsTensor | ||
REQUIRES_PATCH = {} | ||
ACTIVATED_PATCH = {} | ||
|
||
BACKEND_REQUIRES = {} | ||
|
||
|
||
def copy_requires(f): | ||
g = types.FunctionType( | ||
f.__code__, f.__globals__, name=f.__name__, closure=f.__closure__ | ||
) | ||
return functools.update_wrapper(g, f) | ||
|
||
|
||
class rewrite_requires: | ||
class patch_requires: | ||
def __init__(self, tag: str, opname: str): | ||
self.tag = tag | ||
self.opname = opname | ||
|
||
def __call__(self, f): | ||
BACKEND_REQUIRES.setdefault(self.tag, {}).setdefault(self.opname, f) | ||
REQUIRES_PATCH.setdefault(self.tag, {}).setdefault(self.opname, []).append(f) | ||
return f | ||
|
||
|
||
class patch_requires: | ||
def __init__(self, tag: str, opname: str): | ||
self.tag = tag | ||
self.opname = opname | ||
self.prev_fn = None | ||
|
||
def __call__(self, f): | ||
def patch_with_prev(op: AbsOpBase, itensors: List[AbsTensor]): | ||
if self.prev_fn is None: | ||
self.prev_fn = copy_requires(op.requires) | ||
return f(op, itensors) + self.prev_fn(op, itensors) | ||
def activate_ext( | ||
opset: List[Type["AbsOpBase"]], factory: Optional["BackendFactory"] = None | ||
): | ||
for op in opset: | ||
if "global" in REQUIRES_PATCH: | ||
ACTIVATED_PATCH.setdefault(op.name(), []).extend( | ||
REQUIRES_PATCH["global"].get(op.name(), []) | ||
) | ||
|
||
BACKEND_REQUIRES.setdefault(self.tag, {}).setdefault( | ||
self.opname, patch_with_prev | ||
) | ||
return patch_with_prev | ||
if factory is not None and factory.system_name in REQUIRES_PATCH: | ||
ACTIVATED_PATCH.setdefault(op.name(), []).extend( | ||
REQUIRES_PATCH[factory.system_name].get(op.name(), []) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.