Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
def api_current_scope():
    r""" Return current scope
    """
    return oneflow_api.GetCurrentScope()