diff --git a/ivy/compiler/compiler.py b/ivy/compiler/compiler.py index 742149564116f..cf0b26c7c80fe 100644 --- a/ivy/compiler/compiler.py +++ b/ivy/compiler/compiler.py @@ -14,7 +14,7 @@ class LazyGraph: pass -def compile( +def trace( *objs: Callable, stateful: Optional[List] = None, arg_stateful_idxs: Optional[List] = None, @@ -32,16 +32,16 @@ def compile( kwargs: Optional[dict] = None, ) -> Union[Graph, LazyGraph]: if python_version[1] == "8": - from ._compiler_38 import compile as _compile + from ._compiler_38 import trace as _trace else: - from ._compiler import compile as _compile + from ._compiler import trace as _trace """ - Take `fn` and compiles it into a more efficient composition of backend operations. + Take `fn` and decomposes it into a more efficient composition of backend operations. Parameters ---------- objs - callable(s) to compile and create a graph of + callable(s) to trace and create a graph of stateful list of instances to be considered stateful during the graph compilation arg_stateful_idxs @@ -59,7 +59,7 @@ def compile( static_argnames for jax's jit compilation graph_caching - whether to cache the compiled graph + whether to cache the traced graph args positional arguments for `obj` kwargs @@ -67,7 +67,7 @@ def compile( Returns ------- - the compiled `Graph` object. + the traced `Graph` object. Examples -------- @@ -84,8 +84,8 @@ def compile( ... j = ivy.floor(b) ... k = ivy.ceil(c) ... return i, j, k - >>> graph = ivy.compile(fn, args=(x,)) - Notice how the time taken to execute the compiled function is lower than + >>> graph = ivy.trace(fn, args=(x,)) + Notice how the time taken to execute the traced function is lower than the original function. A typical run: >>> start = time.time() >>> fn(x) @@ -96,7 +96,7 @@ def compile( >>> print(time.time() - start) 0.0001785755157470703 """ - return _compile( + return _trace( *objs, stateful=stateful, arg_stateful_idxs=arg_stateful_idxs, diff --git a/ivy/functional/backends/tensorflow/control_flow_ops.py b/ivy/functional/backends/tensorflow/control_flow_ops.py index 9b6f42c456d75..1446e7d58570b 100644 --- a/ivy/functional/backends/tensorflow/control_flow_ops.py +++ b/ivy/functional/backends/tensorflow/control_flow_ops.py @@ -18,7 +18,7 @@ def if_else(cond, body_fn, orelse_fn, vars): cond = bool(cond(*vars)) # return tf.cond(cond, lambda: body_fn(*vars), lambda: orelse_fn(*vars)) - # use pythonic placeholder until the graph compiler supports callable arguments + # use pythonic placeholder until the tracer supports callable arguments if cond: return body_fn(*vars) diff --git a/ivy/functional/ivy/general.py b/ivy/functional/ivy/general.py index b2413ad0de071..fd5b1f7a729d0 100644 --- a/ivy/functional/ivy/general.py +++ b/ivy/functional/ivy/general.py @@ -1662,7 +1662,7 @@ def arg_names(receiver): >>> x = ivy.arg_names(ivy.optimizers.Adam) >>> print(x) ['lr', 'beta1', 'beta2', 'epsilon', 'inplace', - 'stop_gradients', 'compile_on_next_step', 'device'] + 'stop_gradients', 'trace_on_next_step', 'device'] """ return list(inspect.signature(receiver).parameters.keys()) diff --git a/ivy/stateful/module.py b/ivy/stateful/module.py index dc27a344b0a06..a310a812519fa 100644 --- a/ivy/stateful/module.py +++ b/ivy/stateful/module.py @@ -51,12 +51,12 @@ def __init__( v=None, buffers=None, build_mode="on_init", - compile_on_next_step=False, + trace_on_next_step=False, store_vars=True, stateful=None, arg_stateful_idxs=None, kwarg_stateful_idxs=None, - fallback_to_non_compiled=False, + fallback_to_non_traced=False, with_partial_v=False, devices=None, dtype=None, @@ -79,8 +79,8 @@ def __init__( How the Module is built, either on initialization (now), explicitly by the user by calling build(), or the first time the __call__ method is run. Default is on initialization. - compile_on_next_step - Whether to compile the network on the next forward pass. + trace_on_next_step + Whether to trace the network in a graph on the next forward pass. Default is ``False``. store_vars Whether or not to store the variables created. Default is ``True``. @@ -94,9 +94,9 @@ def __init__( kwarg_stateful_idxs The nested keyword argument indices of stateful items to track as part of the forward pass. Used when graph compiling, default is ``None``. - fallback_to_non_compiled - Whether to fall back to non-compiled forward call in the case that an error - is raised during the compiled forward pass. Default is ``True``. + fallback_to_non_traced + Whether to fall back to non-traced forward call in the case that an error + is raised during the traced forward pass. Default is ``True``. with_partial_v Whether to allow partial specification of variables. Default is ``False``. training @@ -121,13 +121,13 @@ def __init__( self._stateful = stateful self._arg_stateful_idxs = arg_stateful_idxs self._kwarg_stateful_idxs = kwarg_stateful_idxs - self._fallback_to_non_compiled = fallback_to_non_compiled + self._fallback_to_non_traced = fallback_to_non_traced self._with_partial_v = with_partial_v self._store_vars = store_vars self._built = False - self._compiled = False - self._compiled_fn = None - self._compile_on_next_step = compile_on_next_step + self._traced = False + self._traced_fn = None + self._trace_on_next_step = trace_on_next_step self._v_in = v if isinstance(v, Container) or v is None else Container(v) self.v = v self.top_v = None @@ -147,7 +147,7 @@ def __init__( self._kwargs = kwargs self._module_graph = None self._target = None - self._lazy_compiled = False + self._lazy_traced = False self._dynamic_backend = dynamic_backend self.training = training if build_mode != "on_init": @@ -627,17 +627,17 @@ def __call__( ------- ret """ - if self._lazy_compiled: - # we are compiling since we want to transpile module, + if self._lazy_traced: + # we are creating graph since we want to transpile module, # so set the appropriate backend if self._target: ivy.set_backend(self._target) - self.compile(args=args, kwargs=kwargs) + self.trace(args=args, kwargs=kwargs) if self._target: ivy.previous_backend() if self._module_graph: - # we need `v` in kwargs, since this is a compiled call + # we need `v` in kwargs, since this is a traced call v = v if v else self.v return self._module_graph(*args, v=v, **kwargs) @@ -857,7 +857,7 @@ def show_graph( fname: Optional[str] = None, ): if not ivy.exists(self._module_graph): - raise ValueError("You must compile the module to display the graph.") + raise ValueError("You must trace the module to display the graph.") return self._module_graph.show( save_to_disk=save_to_disk, @@ -897,28 +897,28 @@ def __delattr__(self, name): else: super().__delattr__(name) - def compile( + def trace( self, args: Optional[Tuple] = None, kwargs: Optional[Dict] = None, - **compile_kwargs, + **trace_kwargs, ): """ - Compile the `ivy.Module`'s `_unified_ivy_graph` or `_call` method to the target + Trace the `ivy.Module`'s `_unified_ivy_graph` or `_call` method to the target backend. Parameters ---------- args: - arguments used to compile. Defaults to None. + arguments used to trace. Defaults to None. kwargs: - keyword arguments used to compile. Defaults to None. - compile_kwargs: - keyword arguments passed to the compile function. + keyword arguments used to trace. Defaults to None. + trace_kwargs: + keyword arguments passed to the trace function. """ - # no arguments given to compile, so delay the compilation + # no arguments given to trace, so delay the compilation if not (args or kwargs): - self._lazy_compiled = True + self._lazy_traced = True return # we do not need convert the args to source @@ -929,13 +929,13 @@ def compile( kwargs = copy.copy(kwargs) kwargs["v"] = self.v - fn_to_compile = ivy.default(self._module_graph, self._call) + fn_to_trace = ivy.default(self._module_graph, self._call) - self._module_graph = ivy.compile( - fn_to_compile, **compile_kwargs, args=args, kwargs=kwargs + self._module_graph = ivy.trace( + fn_to_trace, **trace_kwargs, args=args, kwargs=kwargs ) - self._lazy_compiled = False + self._lazy_traced = False def save(self, filename): """ diff --git a/ivy/stateful/optimizers.py b/ivy/stateful/optimizers.py index 35f3427c04794..fdaafbe4097ac 100644 --- a/ivy/stateful/optimizers.py +++ b/ivy/stateful/optimizers.py @@ -20,8 +20,8 @@ def __init__( inplace: bool = True, stop_gradients: bool = True, init_on_first_step: bool = False, - compile_on_next_step: bool = False, - fallback_to_non_compiled: bool = False, + trace_on_next_step: bool = False, + fallback_to_non_traced: bool = False, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ): """ @@ -42,11 +42,11 @@ def __init__( init_on_first_step Whether the optimizer is initialized on the first step. Default is ``False``. - compile_on_next_step - Whether to compile the optimizer on the next step. Default is ``False``. - fallback_to_non_compiled - Whether to fall back to non-compiled forward call in the case that an error - is raised during the compiled forward pass. Default is ``True``. + trace_on_next_step + Whether to trace the optimizer on the next step. Default is ``False``. + fallback_to_non_traced + Whether to fall back to non-traced forward call in the case that an error + is raised during the traced forward pass. Default is ``True``. device Device on which to create the layer's variables 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None) @@ -56,12 +56,12 @@ def __init__( self._stop_gradients = stop_gradients self._init_on_first_step = init_on_first_step self._initialized = not init_on_first_step - self._compile_on_next_step = compile_on_next_step - self._fallback_to_non_compiled = fallback_to_non_compiled + self._trace_on_next_step = trace_on_next_step + self._fallback_to_non_traced = fallback_to_non_traced self._dev = ivy.default(device, ivy.default_device()) self._count = ivy.array([0], device=self._dev) - self._compiled_step_fn = None - self._compiled = False + self._traced_step_fn = None + self._traced = False # Private # # --------# @@ -167,7 +167,7 @@ def __init__( lr: float = 1e-4, inplace: bool = True, stop_gradients: bool = True, - compile_on_next_step: bool = False, + trace_on_next_step: bool = False, ): """ Construct a Stochastic-Gradient-Descent (SGD) optimizer. @@ -184,11 +184,11 @@ def __init__( stop_gradients Whether to stop the gradients of the variables after each gradient step. Default is ``True``. - compile_on_next_step - Whether to compile the optimizer on the next step. Default is ``False``. + trace_on_next_step + Whether to trace the optimizer on the next step. Default is ``False``. """ Optimizer.__init__( - self, lr, inplace, stop_gradients, compile_on_next_step=compile_on_next_step + self, lr, inplace, stop_gradients, trace_on_next_step=trace_on_next_step ) # Custom Step @@ -240,7 +240,7 @@ def __init__( decay_lambda: float = 0, inplace: bool = True, stop_gradients: bool = True, - compile_on_next_step: bool = False, + trace_on_next_step: bool = False, ): """ Construct a Layer-wise Adaptive Rate Scaling (LARS) optimizer. @@ -259,12 +259,12 @@ def __init__( stop_gradients Whether to stop the gradients of the variables after each gradient step. Default is ``True``. - compile_on_next_step - Whether to compile the optimizer on the next step. Default is ``False``. + trace_on_next_step + Whether to trace the optimizer on the next step. Default is ``False``. """ self._decay_lambda = decay_lambda Optimizer.__init__( - self, lr, inplace, stop_gradients, compile_on_next_step=compile_on_next_step + self, lr, inplace, stop_gradients, trace_on_next_step=trace_on_next_step ) # Custom Step @@ -319,7 +319,7 @@ def __init__( epsilon: float = 1e-07, inplace: bool = True, stop_gradients: bool = True, - compile_on_next_step: bool = False, + trace_on_next_step: bool = False, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ): """ @@ -344,8 +344,8 @@ def __init__( stop_gradients Whether to stop the gradients of the variables after each gradient step. Default is ``True``. - compile_on_next_step - Whether to compile the optimizer on the next step. Default is ``False``. + trace_on_next_step + Whether to trace the optimizer on the next step. Default is ``False``. device Device on which to create the layer's variables 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None) @@ -356,10 +356,10 @@ def __init__( self._mw = None self._vw = None self._first_pass = True - self._should_compile = False + self._should_trace = False Optimizer.__init__( - self, lr, inplace, stop_gradients, True, compile_on_next_step, device=device + self, lr, inplace, stop_gradients, True, trace_on_next_step, device=device ) # Custom Step @@ -428,7 +428,7 @@ def __init__( decay_lambda: float = 0, inplace: bool = True, stop_gradients: bool = True, - compile_on_next_step: bool = False, + trace_on_next_step: bool = False, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ): """ @@ -458,14 +458,14 @@ def __init__( stop_gradients Whether to stop the gradients of the variables after each gradient step. Default is ``True``. - compile_on_next_step - Whether to compile the optimizer on the next step. Default is ``False``. + trace_on_next_step + Whether to trace the optimizer on the next step. Default is ``False``. device Device on which to create the layer's variables 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None) """ Optimizer.__init__( - self, lr, inplace, stop_gradients, True, compile_on_next_step, device=device + self, lr, inplace, stop_gradients, True, trace_on_next_step, device=device ) self._beta1 = beta1 self._beta2 = beta2 diff --git a/ivy/utils/_importlib.py b/ivy/utils/_importlib.py index f6cb3ad3a25c3..ea445ca60d86a 100644 --- a/ivy/utils/_importlib.py +++ b/ivy/utils/_importlib.py @@ -11,7 +11,7 @@ # If they do, the behavior of ivy.with_backend is undefined and may not function as # expected. Import these modules along with Ivy initialization, as the import logic # assumes they exist in sys.modules. -MODULES_TO_SKIP = ["ivy.compiler"] +MODULES_TO_SKIP = ["ivy.compiler"] # ! Are we updating the Compiler Module to Tracer? IS_COMPILING_WITH_BACKEND = False @@ -120,7 +120,9 @@ def _import_module(name, package=None): module = module_from_spec(spec) import_cache[absolute_name] = module if ivy.is_local(): - spec.loader.exec_module(module, ivy._compiled_id) + spec.loader.exec_module( + module, ivy._compiled_id + ) # ! Not sure about what this ID is else: spec.loader.exec_module(module) if path is not None: diff --git a/ivy/utils/exceptions.py b/ivy/utils/exceptions.py index 60518a1e070a3..b93731c1223c3 100644 --- a/ivy/utils/exceptions.py +++ b/ivy/utils/exceptions.py @@ -18,7 +18,7 @@ def _remove_so_log(trace): transpile_frame = None module_frame = None module_st = None - compiled_lineno = None + traced_lineno = None new_stack_trace = [] track = False @@ -27,22 +27,23 @@ def _remove_so_log(trace): if ".pyx" in repr(st): continue if "" in repr(st): - if "compiled_fn" in repr(st) and module_frame: + if "traced_fn" in repr(st) and module_frame: track = True - compiled_lineno = st.lineno + traced_lineno = st.lineno if "" in repr(st): module_frame = old_frames[idx] module_st = st elif ( transpile_frame is None - and os.path.join("ivy", "compiler") in st.filename - and st.name in ["compile", "transpile"] + and os.path.join("ivy", "compiler") + in st.filename # ! Same here, Compiler Module is being updated? + and st.name in ["trace", "transpile"] ): transpile_frame = old_frames[idx] elif track: ret_st = _align_source( - st, transpile_frame, module_frame, module_st, compiled_lineno + st, transpile_frame, module_frame, module_st, traced_lineno ) if ret_st: [new_stack_trace.append(r) for r in ret_st] @@ -55,7 +56,7 @@ def _remove_so_log(trace): return new_stack_trace -def _align_source(st, transpile_frame, module_frame, module_st, compiled_lineno): +def _align_source(st, transpile_frame, module_frame, module_st, traced_lineno): from ivy.compiler.utils.VVX import trace_obj from ivy.compiler.utils.IIV import Graph @@ -78,13 +79,13 @@ def _align_source(st, transpile_frame, module_frame, module_st, compiled_lineno) curr_obj[1] = traced_data[2] curr_obj[2] = v.__name__ - if compiled_lineno: - line = v._Graph__fn_str.split("\n")[compiled_lineno - 1] + if traced_lineno: + line = v._Graph__fn_str.split("\n")[traced_lineno - 1] line = line.split("=")[1].strip() line = line.split("(")[0].strip() target_name = line.split(".")[-1].strip() curr_obj[3] = line - area = compiled_lineno / len(v._Graph__fn_str.strip().split("\n")) + area = traced_lineno / len(v._Graph__fn_str.strip().split("\n")) curr_obj = _get_traces(curr_obj, area, t_v.locals, target_name) diff --git a/ivy_tests/test_docstrings.py b/ivy_tests/test_docstrings.py index 33c2f58c73d7f..9d05e21915d54 100644 --- a/ivy_tests/test_docstrings.py +++ b/ivy_tests/test_docstrings.py @@ -159,7 +159,7 @@ def check_docstring_examples_run( "set_nest_at_indices", "layer_norm", "where", - "compile", + "trace", "eigvalsh", "conv2d_transpose", # fails due to different backend and their view types diff --git a/ivy_tests/test_ivy/conftest.py b/ivy_tests/test_ivy/conftest.py index 3397147cffff9..0005d6e2d5ab9 100644 --- a/ivy_tests/test_ivy/conftest.py +++ b/ivy_tests/test_ivy/conftest.py @@ -51,14 +51,14 @@ def pytest_configure(config): else: backend_strs = raw_value.split(",") - # compile_graph - raw_value = config.getoption("--compile_graph") + # trace_graph + raw_value = config.getoption("--trace_graph") if raw_value == "both": - compile_modes = [True, False] + trace_modes = [True, False] elif raw_value == "true": - compile_modes = [True] + trace_modes = [True] else: - compile_modes = [False] + trace_modes = [False] # implicit raw_value = config.getoption("--with_implicit") @@ -76,13 +76,13 @@ def pytest_configure(config): in UNSUPPORTED_FRAEMWORK_DEVICES[backend_str] ): continue - for compile_graph in compile_modes: + for trace_graph in trace_modes: for implicit in implicit_modes: TEST_PARAMS_CONFIG.append( ( device, backend_str, - compile_graph, + trace_graph, implicit, ) ) @@ -91,7 +91,7 @@ def pytest_configure(config): @pytest.fixture(autouse=True) -def run_around_tests(request, on_device, backend_fw, compile_graph, implicit): +def run_around_tests(request, on_device, backend_fw, trace_graph, implicit): try: test_globals.setup_api_test( backend_fw, @@ -128,11 +128,11 @@ def pytest_generate_tests(metafunc): if entry[1] == metafunc.function.ground_truth_backend: test_paramters.remove(entry) metafunc.parametrize( - "on_device,backend_fw,compile_graph,implicit", test_paramters + "on_device,backend_fw,trace_graph,implicit", test_paramters ) else: metafunc.parametrize( - "on_device,backend_fw,compile_graph,implicit", TEST_PARAMS_CONFIG + "on_device,backend_fw,trace_graph,implicit", TEST_PARAMS_CONFIG ) @@ -165,9 +165,9 @@ def process_cl_flags(config) -> Dict[str, bool]: getopt("--skip-gradient-testing"), getopt("--with-gradient-testing"), ), - "test_compile": ( - getopt("--skip-compile-testing"), - getopt("--with-compile-testing"), + "test_trace": ( + getopt("--skip-trace-testing"), + getopt("--with-trace-testing"), ), } @@ -195,7 +195,7 @@ def process_cl_flags(config) -> Dict[str, bool]: def pytest_addoption(parser): parser.addoption("--device", action="store", default="cpu") parser.addoption("-B", "--backend", action="store", default="all") - parser.addoption("--compile_graph", action="store_true") + parser.addoption("--trace_graph", action="store_true") parser.addoption("--with_implicit", action="store_true") parser.addoption("--frontend", action="store", default=None) parser.addoption("--env", action="store", default=None) @@ -206,7 +206,7 @@ def pytest_addoption(parser): parser.addoption("--skip-nestable-testing", action="store_true") parser.addoption("--skip-instance-method-testing", action="store_true") parser.addoption("--skip-gradient-testing", action="store_true") - parser.addoption("--skip-compile-testing", action="store_true") + parser.addoption("--skip-trace-testing", action="store_true") parser.addoption("--with-variable-testing", action="store_true") parser.addoption("--with-native-array-testing", action="store_true") @@ -214,7 +214,7 @@ def pytest_addoption(parser): parser.addoption("--with-nestable-testing", action="store_true") parser.addoption("--with-instance-method-testing", action="store_true") parser.addoption("--with-gradient-testing", action="store_true") - parser.addoption("--with-compile-testing", action="store_true") + parser.addoption("--with-trace-testing", action="store_true") parser.addoption("--no-extra-testing", action="store_true") parser.addoption( "--my_test_dump", diff --git a/ivy_tests/test_ivy/helpers/function_testing.py b/ivy_tests/test_ivy/helpers/function_testing.py index 02315785cbf26..1ab8845b0de1b 100644 --- a/ivy_tests/test_ivy/helpers/function_testing.py +++ b/ivy_tests/test_ivy/helpers/function_testing.py @@ -30,10 +30,10 @@ # Temporary (.so) configuration -def compiled_if_required(backend: str, fn, test_compile=False, args=None, kwargs=None): +def traced_if_required(backend: str, fn, test_trace=False, args=None, kwargs=None): with BackendHandler.update_backend(backend) as ivy_backend: - if test_compile: - fn = ivy_backend.compile(fn, args=args, kwargs=kwargs) + if test_trace: + fn = ivy_backend.trace(fn, args=args, kwargs=kwargs) return fn @@ -196,7 +196,7 @@ def test_function( >>> test_function(input_dtypes, test_flags, fw, fn_name, x1=x1, x2=x2) """ # ToDo add with_backend refactor in GC - _switch_backend_context(test_flags.test_compile) + _switch_backend_context(test_flags.test_trace) # split the arguments into their positional and keyword components args_np, kwargs_np = kwargs_to_args_n_kwargs( @@ -288,7 +288,7 @@ def test_function( backend_to_test, kwargs, arrays_kwargs_indices, kwargs_instance_mask ) - if test_flags.test_compile: + if test_flags.test_trace: target_fn = lambda instance, *args, **kwargs: instance.__getattribute__( fn_name )(*args, **kwargs) @@ -302,7 +302,7 @@ def test_function( backend_to_test, target_fn, *args, - test_compile=test_flags.test_compile, + test_trace=test_flags.test_trace, precision_mode=test_flags.precision_mode, **kwargs, ) @@ -313,7 +313,7 @@ def test_function( ), "Ivy function returned non-ivy arrays: {}".format(ret_from_target) # Assert indices of return if the indices of the out array provided - if test_flags.with_out and not test_flags.test_compile: + if test_flags.with_out and not test_flags.test_trace: test_ret = ( ret_from_target[getattr(ivy_backend.__dict__[fn_name], "out_index")] if hasattr(ivy_backend.__dict__[fn_name], "out_index") @@ -413,7 +413,7 @@ def test_function( test_flags.ground_truth_backend, gt_backend.__dict__[fn_name], *args, - test_compile=test_flags.test_compile, + test_trace=test_flags.test_trace, precision_mode=test_flags.precision_mode, **kwargs, ) @@ -421,7 +421,7 @@ def test_function( ret_from_gt, lambda x: gt_backend.is_ivy_array(x) if gt_backend.is_array(x) else True, ), "Ground-truth function returned non-ivy arrays: {}".format(ret_from_gt) - if test_flags.with_out and not test_flags.test_compile: + if test_flags.with_out and not test_flags.test_trace: test_ret_from_gt = ( ret_from_gt[getattr(gt_backend.__dict__[fn_name], "out_index")] if hasattr(gt_backend.__dict__[fn_name], "out_index") @@ -437,7 +437,7 @@ def test_function( test_flags.ground_truth_backend, gt_backend.__dict__[fn_name], *args, - test_compile=test_flags.test_compile, + test_trace=test_flags.test_trace, precision_mode=test_flags.precision_mode, **kwargs, out=out_from_gt, @@ -571,7 +571,7 @@ def test_frontend_function( optional, return value from the Numpy function """ # ToDo add with_backend refactor in GC - _switch_backend_context(test_flags.test_compile) + _switch_backend_context(test_flags.test_trace) assert ( not test_flags.with_out or not test_flags.inplace @@ -663,9 +663,9 @@ def test_frontend_function( backend_to_test, frontend_fn, *args_for_test, - test_compile=test_flags.test_compile, + test_trace=test_flags.test_trace, frontend_array_function=( - create_frontend_array if test_flags.test_compile else None + create_frontend_array if test_flags.test_trace else None ), as_ivy_arrays=(not test_flags.generate_frontend_arrays), precision_mode=test_flags.precision_mode, @@ -757,7 +757,7 @@ def test_frontend_function( elif test_flags.inplace: assert not isinstance(ret, tuple) - if test_flags.generate_frontend_arrays and not test_flags.test_compile: + if test_flags.generate_frontend_arrays and not test_flags.test_trace: assert _is_frontend_array(ret) array_fn = _is_frontend_array else: @@ -778,9 +778,9 @@ def test_frontend_function( frontend_fn=frontend_fn, backend=backend_to_test, precision_mode=test_flags.precision_mode, - test_compile=test_flags.test_compile, + test_trace=test_flags.test_trace, frontend_array_function=( - create_frontend_array if test_flags.test_compile else None + create_frontend_array if test_flags.test_trace else None ), *copy_args, **copy_kwargs, @@ -797,9 +797,9 @@ def test_frontend_function( frontend_fn=frontend_fn, backend=backend_to_test, precision_mode=test_flags.precision_mode, - test_compile=test_flags.test_compile, + test_trace=test_flags.test_trace, frontend_array_function=( - create_frontend_array if test_flags.test_compile else None + create_frontend_array if test_flags.test_trace else None ), *args, **kwargs, @@ -923,7 +923,7 @@ def gradient_test( kwargs_np, input_dtypes, test_flags, - test_compile: bool = False, + test_trace: bool = False, rtol_: float = None, atol_: float = 1e-06, tolerance_dict: dict = None, @@ -955,10 +955,10 @@ def gradient_test( def _grad_fn(all_args): args, kwargs, i = all_args call_fn = ivy_backend.__dict__[fn] if isinstance(fn, str) else fn[i] - ret = compiled_if_required( + ret = traced_if_required( backend_to_test, call_fn, - test_compile=test_compile, + test_trace=test_trace, args=args, kwargs=kwargs, )(*args, **kwargs) @@ -999,10 +999,10 @@ def _grad_fn(all_args): def _gt_grad_fn(all_args): args, kwargs, i = all_args call_fn = gt_backend.__dict__[fn] if isinstance(fn, str) else fn[i] - ret = compiled_if_required( + ret = traced_if_required( ground_truth_backend, call_fn, - test_compile=test_compile, + test_trace=test_trace, args=args, kwargs=kwargs, )(*args, **kwargs) @@ -1058,7 +1058,7 @@ def test_method( test_gradients: bool = False, xs_grad_idxs=None, ret_grad_idxs=None, - test_compile: bool = False, + test_trace: bool = False, backend_to_test: str, ground_truth_backend: str, on_device: str, @@ -1126,7 +1126,7 @@ def test_method( ret_grad_idxs Indices of the returned arrays for which to return computed gradients. If None, gradients are returned for all returned arrays. (Default value = None) - test_compile + test_trace If True, test for the correctness of compilation. ground_truth_backend Ground Truth Backend to compare the result-values. @@ -1144,7 +1144,7 @@ def test_method( optional, return value from the Ground Truth function """ # ToDo add with_backend refactor in GC - _switch_backend_context(test_compile) + _switch_backend_context(test_trace) init_input_dtypes = ivy.default(init_input_dtypes, []) @@ -1292,7 +1292,7 @@ def test_method( backend_to_test, ins.__getattribute__(method_name), *args_method, - test_compile=test_compile, + test_trace=test_trace, precision_mode=method_flags.precision_mode, **kwargs_method, ) @@ -1346,7 +1346,7 @@ def test_method( ground_truth_backend, ins_gt.__getattribute__(method_name), *args_gt_method, - test_compile=test_compile, + test_trace=test_trace, precision_mode=method_flags.precision_mode, **kwargs_gt_method, ) @@ -1397,7 +1397,7 @@ def test_method( kwargs_np=kwargs_np_method, input_dtypes=method_input_dtypes, test_flags=method_flags, - test_compile=test_compile, + test_trace=test_trace, rtol_=rtol_, atol_=atol_, tolerance_dict=tolerance_dict, @@ -1419,7 +1419,7 @@ def test_method( kwargs_np=kwargs_np_method, input_dtypes=method_input_dtypes, test_flags=method_flags, - test_compile=test_compile, + test_trace=test_trace, rtol_=rtol_, atol_=atol_, tolerance_dict=tolerance_dict, @@ -1524,7 +1524,7 @@ def test_frontend_method( optional, return value from the Ground Truth function """ # ToDo add with_backend refactor in GC - _switch_backend_context(method_flags.test_compile) + _switch_backend_context(method_flags.test_trace) # Constructor arguments # args_np_constructor, kwargs_np_constructor = kwargs_to_args_n_kwargs( @@ -1679,7 +1679,7 @@ def test_frontend_method( ins.__getattribute__(frontend_method_data.method_name), precision_mode=method_flags.precision_mode, *args_method, - test_compile=method_flags.test_compile, + test_trace=method_flags.test_trace, **kwargs_method, ) @@ -1974,15 +1974,15 @@ def flatten_frontend_to_np(*, backend: str, ret, frontend_array_fn=None): def get_ret_and_flattened_np_array( - backend_to_test: str, fn, *args, test_compile=False, precision_mode=False, **kwargs + backend_to_test: str, fn, *args, test_trace=False, precision_mode=False, **kwargs ): """ Run func with args and kwargs. Return the result along with its flattened version. """ - fn = compiled_if_required( - backend_to_test, fn, test_compile=test_compile, args=args, kwargs=kwargs + fn = traced_if_required( + backend_to_test, fn, test_trace=test_trace, args=args, kwargs=kwargs ) with BackendHandler.update_backend(backend_to_test) as ivy_backend: with ivy_backend.PreciseMode(precision_mode): @@ -2006,20 +2006,20 @@ def get_frontend_ret( frontend_array_function=None, as_ivy_arrays=True, precision_mode=False, - test_compile: bool = False, + test_trace: bool = False, **kwargs, ): - frontend_fn = compiled_if_required( - backend, frontend_fn, test_compile=test_compile, args=args, kwargs=kwargs + frontend_fn = traced_if_required( + backend, frontend_fn, test_trace=test_trace, args=args, kwargs=kwargs ) with BackendHandler.update_backend(backend) as ivy_backend: - if not as_ivy_arrays and test_compile: + if not as_ivy_arrays and test_trace: args, kwargs = ivy_backend.nested_map( (args, kwargs), _frontend_array_to_ivy, include_derived={tuple: True} ) with ivy_backend.PreciseMode(precision_mode): ret = frontend_fn(*args, **kwargs) - if test_compile and frontend_array_function is not None: + if test_trace and frontend_array_function is not None: if as_ivy_arrays: ret = ivy_backend.nested_map( ret, ivy_backend.asarray, include_derived={tuple: True} @@ -2132,8 +2132,8 @@ def _new_fn(x, *args, **kwargs): return _new_fn -def _switch_backend_context(compile: bool): - if compile: +def _switch_backend_context(trace: bool): + if trace: BackendHandler._update_context(BackendHandlerMode.SetBackend) else: ( diff --git a/ivy_tests/test_ivy/helpers/test_parameter_flags.py b/ivy_tests/test_ivy/helpers/test_parameter_flags.py index be0395e883262..ff3e4919e491b 100644 --- a/ivy_tests/test_ivy/helpers/test_parameter_flags.py +++ b/ivy_tests/test_ivy/helpers/test_parameter_flags.py @@ -34,7 +34,7 @@ def _as_varaible_strategy(draw): BuiltInplaceStrategy = st.just(False) BuiltGradientStrategy = _gradient_strategy() BuiltWithOutStrategy = st.booleans() -BuiltCompileStrategy = st.just(False) +BuiltTraceStrategy = st.just(False) BuiltFrontendArrayStrategy = st.booleans() BuiltPrecisionModeStrategy = st.booleans() @@ -47,7 +47,7 @@ def _as_varaible_strategy(draw): "test_gradients": "BuiltGradientStrategy", "with_out": "BuiltWithOutStrategy", "inplace": "BuiltInplace", - "test_compile": "BuiltCompileStrategy", + "test_trace": "BuiltTraceStrategy", "precision_mode": "BuiltPrecisionModeStrategy", } @@ -81,7 +81,7 @@ def __init__( native_arrays, container, test_gradients, - test_compile, + test_trace, precision_mode, ): self.ground_truth_backend = ground_truth_backend @@ -92,7 +92,7 @@ def __init__( self.container = container self.as_variable = as_variable self.test_gradients = test_gradients - self.test_compile = test_compile + self.test_trace = test_trace self.precision_mode = precision_mode def apply_flags(self, args_to_iterate, input_dtypes, offset, *, backend, on_device): @@ -119,7 +119,7 @@ def __str__(self): f"container={self.container}. " f"as_variable={self.as_variable}. " f"test_gradients={self.test_gradients}. " - f"test_compile={self.test_compile}. " + f"test_trace={self.test_trace}. " f"precision_mode={self.precision_mode}. " ) @@ -136,7 +136,7 @@ def function_flags( instance_method, with_out, test_gradients, - test_compile, + test_trace, as_variable, native_arrays, container_flags, @@ -150,7 +150,7 @@ def function_flags( with_out=with_out, instance_method=instance_method, test_gradients=test_gradients, - test_compile=test_compile, + test_trace=test_trace, as_variable=as_variable, native_arrays=native_arrays, container=container_flags, @@ -167,7 +167,7 @@ def __init__( inplace, as_variable, native_arrays, - test_compile, + test_trace, generate_frontend_arrays, precision_mode, ): @@ -176,7 +176,7 @@ def __init__( self.inplace = inplace self.native_arrays = native_arrays self.as_variable = as_variable - self.test_compile = test_compile + self.test_trace = test_trace self.generate_frontend_arrays = generate_frontend_arrays self.precision_mode = precision_mode @@ -199,7 +199,7 @@ def __str__(self): f"inplace={self.inplace}. " f"native_arrays={self.native_arrays}. " f"as_variable={self.as_variable}. " - f"test_compile={self.test_compile}. " + f"test_trace={self.test_trace}. " f"generate_frontend_arrays={self.generate_frontend_arrays}. " f"precision_mode={self.precision_mode}. " ) @@ -217,7 +217,7 @@ def frontend_function_flags( inplace, as_variable, native_arrays, - test_compile, + test_trace, generate_frontend_arrays, precision_mode, ): @@ -229,7 +229,7 @@ def frontend_function_flags( inplace=inplace, as_variable=as_variable, native_arrays=native_arrays, - test_compile=test_compile, + test_trace=test_trace, generate_frontend_arrays=generate_frontend_arrays, precision_mode=precision_mode, ) @@ -364,13 +364,13 @@ def __init__( as_variable, native_arrays, precision_mode, - test_compile, + test_trace, ): self.num_positional_args = num_positional_args self.native_arrays = native_arrays self.as_variable = as_variable self.precision_mode = precision_mode - self.test_compile = test_compile + self.test_trace = test_trace def apply_flags(self, args_to_iterate, input_dtypes, offset, *, backend, on_device): ret = [] @@ -390,7 +390,7 @@ def __str__(self): f"native_arrays={self.native_arrays}. " f"as_variable={self.as_variable}. " f"precision_mode={self.precision_mode}. " - f"test_compile={self.test_compile}." + f"test_trace={self.test_trace}." ) def __repr__(self): @@ -405,7 +405,7 @@ def frontend_method_flags( as_variable, native_arrays, precision_mode, - test_compile, + test_trace, ): return draw( st.builds( @@ -414,6 +414,6 @@ def frontend_method_flags( as_variable=as_variable, native_arrays=native_arrays, precision_mode=precision_mode, - test_compile=test_compile, + test_trace=test_trace, ) ) diff --git a/ivy_tests/test_ivy/helpers/testing_helpers.py b/ivy_tests/test_ivy/helpers/testing_helpers.py index 670f6106ac880..435b9139b9a8d 100644 --- a/ivy_tests/test_ivy/helpers/testing_helpers.py +++ b/ivy_tests/test_ivy/helpers/testing_helpers.py @@ -22,7 +22,7 @@ BuiltContainerStrategy, BuiltWithOutStrategy, BuiltInplaceStrategy, - BuiltCompileStrategy, + BuiltTraceStrategy, BuiltFrontendArrayStrategy, BuiltPrecisionModeStrategy, ) @@ -38,7 +38,7 @@ "with_out", "instance_method", "test_gradients", - "test_compile", + "test_trace", "precision_mode", ) cmd_line_args_lists = ( @@ -287,7 +287,7 @@ def handle_test( test_instance_method=BuiltInstanceStrategy, test_with_out=BuiltWithOutStrategy, test_gradients=BuiltGradientStrategy, - test_compile=BuiltCompileStrategy, + test_trace=BuiltTraceStrategy, precision_mode=BuiltPrecisionModeStrategy, as_variable_flags=BuiltAsVariableStrategy, native_array_flags=BuiltNativeArrayStrategy, @@ -322,8 +322,8 @@ def handle_test( A search strategy that generates a boolean to test the function with arrays as gradients - test_compile - A search strategy that generates a boolean to graph compile and test the + test_trace + A search strategy that generates a boolean to trace and test the function precision_mode @@ -359,7 +359,7 @@ def handle_test( instance_method=test_instance_method, with_out=test_with_out, test_gradients=test_gradients, - test_compile=test_compile, + test_trace=test_trace, as_variable=as_variable_flags, native_arrays=native_array_flags, container_flags=container_flags, @@ -424,7 +424,7 @@ def handle_frontend_test( test_inplace=BuiltInplaceStrategy, as_variable_flags=BuiltAsVariableStrategy, native_array_flags=BuiltNativeArrayStrategy, - test_compile=BuiltCompileStrategy, + test_trace=BuiltTraceStrategy, generate_frontend_arrays=BuiltFrontendArrayStrategy, precision_mode=BuiltPrecisionModeStrategy, **_given_kwargs, @@ -465,8 +465,8 @@ def handle_frontend_test( A search strategy that generates a list of boolean flags for array inputs to be passed as a native array - test_compile - A search strategy that generates a boolean to graph compile and test the + test_trace + A search strategy that generates a boolean to trace and test the function generate_frontend_arrays @@ -490,7 +490,7 @@ def handle_frontend_test( inplace=test_inplace, as_variable=as_variable_flags, native_arrays=native_array_flags, - test_compile=test_compile, + test_trace=test_trace, generate_frontend_arrays=generate_frontend_arrays, precision_mode=precision_mode, ) @@ -563,7 +563,7 @@ def handle_method( method_tree: str = None, ground_truth_backend: str = "tensorflow", test_gradients=BuiltGradientStrategy, - test_compile=BuiltCompileStrategy, + test_trace=BuiltTraceStrategy, precision_mode=BuiltPrecisionModeStrategy, init_num_positional_args=None, init_native_arrays=BuiltNativeArrayStrategy, @@ -595,7 +595,7 @@ def handle_method( possible_arguments = { "ground_truth_backend": st.just(ground_truth_backend), "test_gradients": test_gradients, - "test_compile": test_compile, + "test_trace": test_trace, "precision_mode": precision_mode, } @@ -684,7 +684,7 @@ def handle_frontend_method( init_num_positional_args=None, init_native_arrays=BuiltNativeArrayStrategy, init_as_variable_flags=BuiltAsVariableStrategy, - test_compile=BuiltCompileStrategy, + test_trace=BuiltTraceStrategy, precision_mode=BuiltPrecisionModeStrategy, method_num_positional_args=None, method_native_arrays=BuiltNativeArrayStrategy, @@ -744,7 +744,7 @@ def test_wrapper(test_fn): num_positional_args=init_num_positional_args, as_variable=init_as_variable_flags, native_arrays=init_native_arrays, - test_compile=test_compile, + test_trace=test_trace, precision_mode=precision_mode, ) @@ -752,7 +752,7 @@ def test_wrapper(test_fn): num_positional_args=method_num_positional_args, as_variable=method_as_variable_flags, native_arrays=method_native_arrays, - test_compile=test_compile, + test_trace=test_trace, precision_mode=precision_mode, ) ivy_init_modules = str(ivy_init_module) diff --git a/ivy_tests/test_ivy/test_frontends/conftest.py b/ivy_tests/test_ivy/test_frontends/conftest.py index a9b13baa40d67..649a2b5769cab 100644 --- a/ivy_tests/test_ivy/test_frontends/conftest.py +++ b/ivy_tests/test_ivy/test_frontends/conftest.py @@ -4,7 +4,7 @@ @pytest.fixture(autouse=True) -def run_around_tests(request, on_device, backend_fw, frontend, compile_graph, implicit): +def run_around_tests(request, on_device, backend_fw, frontend, trace_graph, implicit): try: test_globals.setup_frontend_test( frontend, diff --git a/ivy_tests/test_ivy/test_misc/test_with_backend.py b/ivy_tests/test_ivy/test_misc/test_with_backend.py index 9525194141cd5..4f9212a7874c1 100644 --- a/ivy_tests/test_ivy/test_misc/test_with_backend.py +++ b/ivy_tests/test_ivy/test_misc/test_with_backend.py @@ -10,7 +10,7 @@ @pytest.fixture -def compiled_backends(): +def compiled_backends(): # ! I assume this is about "compilation" of backends compiled_backends = [] for b in _backend_dict: _b = ivy.with_backend(b) diff --git a/ivy_tests/test_ivy/test_stateful/test_layers.py b/ivy_tests/test_ivy/test_stateful/test_layers.py index 6326496eda3dd..84730074762fb 100644 --- a/ivy_tests/test_ivy/test_stateful/test_layers.py +++ b/ivy_tests/test_ivy/test_stateful/test_layers.py @@ -1541,7 +1541,7 @@ def test_sequential_layer( dtype, method_flags, on_device, - compile_graph, + trace_graph, method_name, class_name, ): diff --git a/scripts/eager_mode_benchmark/benchmark.py b/scripts/eager_mode_benchmark/benchmark.py index 6926b825b3cad..1c9cc4fd0ed76 100644 --- a/scripts/eager_mode_benchmark/benchmark.py +++ b/scripts/eager_mode_benchmark/benchmark.py @@ -5,6 +5,7 @@ import copy import importlib import warnings + import numpy as np import pandas as pd import matplotlib.pyplot as plt @@ -232,17 +233,17 @@ def eager_benchmark( ) if isinstance(obj_call, ivy.Module): obj_call_copy = copy.deepcopy(obj_call) - obj_call_copy.compile(args=args, kwargs=kwargs) - compiled_fn = obj_call_copy + obj_call_copy.trace(args=args, kwargs=kwargs) + traced_fn = obj_call_copy else: - compiled_fn = ivy.compile(obj_call, args=args, kwargs=kwargs) + traced_fn = ivy.trace(obj_call, args=args, kwargs=kwargs) kwargs = ivy.default(kwargs, {}) args = ivy.default(args, ()) - uncompiled_time = _compute_time(obj_call)(*args, **kwargs) - compiled_time = _compute_time(compiled_fn)(*args, **kwargs) + untraced_time = _compute_time(obj_call)(*args, **kwargs) + traced_time = _compute_time(traced_fn)(*args, **kwargs) label = obj_call.__name__ if label is None else label percent_speed_up = round( - abs(uncompiled_time - compiled_time) / uncompiled_time * 100, 6 + abs(untraced_time - traced_time) / untraced_time * 100, 6 ) df = _read_or_create_csv(output_path) _write_to_csv( @@ -252,8 +253,8 @@ def eager_benchmark( label, backend, device, - uncompiled_time, - compiled_time, + untraced_time, + traced_time, percent_speed_up, ], output_path,