python/tvm/relay/transform.py
def function_pass(pass_func=None, opt_level=None, name=None, required=None):
    """Create a function pass. This function returns a callback when pass_func
    is provided. Otherwise, it returns the created function pass using the
    given optimization function.

    Parameters
    ----------
    pass_func : Optional[Callable[(Module/Function, PassContext) ->
                Module/Function]]
        The implemented optimization pass.

    opt_level : int
        The optimization level of this module pass.

    name : Optional[str]
        The name of the function pass. The name could be empty. In this case, the
        name of the optimization function will be used as the pass name.

    required : Optional[List[str]]
        The list of passes that the module pass is dependent on.

    Returns
    -------
    create_function_pass : Union[Callable, FunctionPass]
        The callable that will create a function pass is returned when
        pass_func is not passed in. Otherwise, a FunctionPass object will be
        created.

    Examples
    --------
    The following code creates a function level pass that performs constant
    folding.

    .. code-block:: python

        @relay.transform.function_pass(opt_level=2)
        def transform(func, ctx):
            return ir_pass.fold_constant(func)

        function_pass = transform
        assert isinstance(function_pass, transform.FunctionPass)
        assert function_pass.info.opt_level == 2

        # Given a module m, the optimization could be invoked as the follwoing:
        updated_mod = function_pass(m)
        # Now constant folding should have been applied to every function in
        # the provided module m. And the updated module will be returned.
    """

    if opt_level is None:
        raise ValueError("Please provide opt_level for the funtion pass.")

    required = required if required else []
    if not isinstance(required, (list, tuple)):
        raise TypeError("Required is expected to be the type of " +
                        "list/tuple.")

    def create_function_pass(pass_func):
        """Internal function that creates a function pass"""
        if not isinstance(pass_func, (types.FunctionType, types.LambdaType)):
            raise TypeError("pass_func must be a callable for Module pass")

        fname = name if name else pass_func.__name__
        info = PassInfo(opt_level, fname, required)
        return _transform.MakeFunctionPass(pass_func, info)

    if pass_func:
        return create_function_pass(pass_func)
    return create_function_pass
Create a function pass. This function returns a callback when pass_func
    is provided. Otherwise, it returns the created function pass using the
    given optimization function.

    Parameters
    ----------
    pass_func : Optional[Callable[(Module/Function, PassContext) ->
                Module/Function]]
        The implemented optimization pass.

    opt_level : int
        The optimization level of this module pass.

    name : Optional[str]
        The name of the function pass. The name could be empty. In this case, the
        name of the optimization function will be used as the pass name.

    required : Optional[List[str]]
        The list of passes that the module pass is dependent on.

    Returns
    -------
    create_function_pass : Union[Callable, FunctionPass]
        The callable that will create a function pass is returned when
        pass_func is not passed in. Otherwise, a FunctionPass object will be
        created.

    Examples
    --------
    The following code creates a function level pass that performs constant
    folding.

    .. code-block:: python

        @relay.transform.function_pass(opt_level=2)
        def transform(func, ctx):
            return ir_pass.fold_constant(func)

        function_pass = transform
        assert isinstance(function_pass, transform.FunctionPass)
        assert function_pass.info.opt_level == 2

        # Given a module m, the optimization could be invoked as the follwoing:
        updated_mod = function_pass(m)
        # Now constant folding should have been applied to every function in
        # the provided module m. And the updated module will be returned.
    
Create a function pass. This function returns a callback when pass_func
is provided. Otherwise, it returns the created function pass using the
given optimization function.

Parameters

pass_func : Optional[Callable[(Module/Function, PassContext) ->
Module/Function]]
The implemented optimization pass.

opt_level : int
The optimization level of this module pass.

name : Optional[str]
The name of the function pass. The name could be empty. In this case, the
name of the optimization function will be used as the pass name.

required : Optional[List[str]]
The list of passes that the module pass is dependent on.

Returns

create_function_pass : Union[Callable, FunctionPass]
The callable that will create a function pass is returned when
pass_func is not passed in. Otherwise, a FunctionPass object will be
created.

Examples

The following code creates a function level pass that performs constant
folding.

code-block:: python





Given a module m, the optimization could be invoked as the follwoing:
updated_mod = function_pass(m)
Now constant folding should have been applied to every function in
the provided module m. And the updated module will be returned.
Create a function pass . This function returns a callback when pass_func is provided . Otherwise it returns the created function pass using the given optimization function . Parameters pass_func : Optional [ Callable [ ( Module / Function PassContext ) - > Module / Function ]] The implemented optimization pass . opt_level : int The optimization level of this module pass . name : Optional [ str ] The name of the function pass . The name could be empty . In this case the name of the optimization function will be used as the pass name . required : Optional [ List [ str ]] The list of passes that the module pass is dependent on . Returns create_function_pass : Union [ Callable FunctionPass ] The callable that will create a function pass is returned when pass_func is not passed in . Otherwise a FunctionPass object will be created . Examples The following code creates a function level pass that performs constant folding . code - block :: python Given a module m the optimization could be invoked as the follwoing : updated_mod = function_pass ( m ) Now constant folding should have been applied to every function in the provided module m . And the updated module will be returned .
def function_pass(pass_func=None, opt_level=None, name=None, required=None):
    if opt_level is None:
        raise ValueError("Please provide opt_level for the funtion pass.")
    required = required if required else []
    if not isinstance(required, (list, tuple)):
        raise TypeError("Required is expected to be the type of " +
                        "list/tuple.")
    def create_function_pass(pass_func):
        if not isinstance(pass_func, (types.FunctionType, types.LambdaType)):
            raise TypeError("pass_func must be a callable for Module pass")
        fname = name if name else pass_func.__name__
        info = PassInfo(opt_level, fname, required)
        return _transform.MakeFunctionPass(pass_func, info)
    if pass_func:
        return create_function_pass(pass_func)
    return create_function_pass
def function_pass ( pass_func = None , opt_level = None , name = None , required = None ) : if opt_level is None : raise ValueError ( "Please provide opt_level for the funtion pass." ) required = required if required else [ ] if not isinstance ( required , ( list , tuple ) ) : raise TypeError ( "Required is expected to be the type of " + "list/tuple." ) def create_function_pass ( pass_func ) : """Internal function that creates a function pass""" if not isinstance ( pass_func , ( types . FunctionType , types . LambdaType ) ) : raise TypeError ( "pass_func must be a callable for Module pass" ) fname = name if name else pass_func . __name__ info = PassInfo ( opt_level , fname , required ) return _transform . MakeFunctionPass ( pass_func , info ) if pass_func : return create_function_pass ( pass_func ) return create_function_pass
Create a function pass.
Create a function pass .
"""Create a function pass. This function returns a callback when pass_func
    is provided. Otherwise, it returns the created function pass using the
    given optimization function.

    Parameters
    ----------
    pass_func : Optional[Callable[(Module/Function, PassContext) ->
                Module/Function]]
        The implemented optimization pass.

    opt_level : int
        The optimization level of this module pass.

    name : Optional[str]
        The name of the function pass. The name could be empty. In this case, the
        name of the optimization function will be used as the pass name.

    required : Optional[List[str]]
        The list of passes that the module pass is dependent on.

    Returns
    -------
    create_function_pass : Union[Callable, FunctionPass]
        The callable that will create a function pass is returned when
        pass_func is not passed in. Otherwise, a FunctionPass object will be
        created.

    Examples
    --------
    The following code creates a function level pass that performs constant
    folding.

    .. code-block:: python

        @relay.transform.function_pass(opt_level=2)
        def transform(func, ctx):
            return ir_pass.fold_constant(func)

        function_pass = transform
        assert isinstance(function_pass, transform.FunctionPass)
        assert function_pass.info.opt_level == 2

        # Given a module m, the optimization could be invoked as the follwoing:
        updated_mod = function_pass(m)
        # Now constant folding should have been applied to every function in
        # the provided module m. And the updated module will be returned.
    """ """Internal function that creates a function pass"""
pass_func
opt_level
name
required