def ScopeContext(scope): old_scope = oneflow_api.GetCurrentScope() oneflow_api.GlobalScopeStackPush(scope) try: yield finally: assert oneflow_api.GetCurrentScope() is scope oneflow_api.GlobalScopeStackPop() assert oneflow_api.GetCurrentScope() is old_scope
def MakeScope(build_func): scope = None old_scope = oneflow_api.GetCurrentScope() assert old_scope is not None def BuildScope(builder): nonlocal scope scope = build_func(old_scope, builder) assert scope is not None oneflow_api.deprecated.LogicalRun(BuildScope) return scope
def api_current_scope(): r""" Return current scope """ return oneflow_api.GetCurrentScope()