code: def test_fomaml_step_overlapping_vars(
      on_device,
      inner_grad_steps,
      with_outer_cost_fn,
      average_across_steps,
      batched,
      stop_gradients,
      num_tasks,
      return_inner_v,
      backend_fw,
  ):
      # Numpy does not support gradients, jax does not support gradients on custom
      # nested classes
      if backend_fw == "numpy":
          pytest.skip()
  
      with BackendHandler.update_backend(backend_fw) as ivy_backend:
          # config
          inner_learning_rate = 1e-2
          variable_fn = ivy_backend.functional.ivy._variable
  
          # create variables
          if batched:
              variables = ivy_backend.Container(
                  {
                      "latent": variable_fn(
                          ivy_backend.repeat(
                              ivy_backend.array(
                                  [[0.0]], device=on_device
                              ),
                              num_tasks,
                              axis=0,
                          )
                      ),
                      "weight": variable_fn(
                          ivy_backend.repeat(
                              ivy_backend.array(
                                  [[1.0]], device=on_device
                              ),
                              num_tasks,
                              axis=0,
                          )
                      ),
                  }
              )
          else:
              variables = ivy_backend.Container(
                  {
                      "latent": variable_fn(
                          ivy_backend.array([0.0], device=on_device)
                      ),
                      "weight": variable_fn(
                          ivy_backend.array([1.0], device=on_device)
                      ),
                  }
              )
  
          # batch
          batch = ivy_backend.Container(
              {
                  "x": ivy_backend.arange(
                      1, num_tasks + 1, dtype="float32"
                  )
              }
          )
  
          # inner cost function
          def inner_cost_fn(batch_in, v):
              cost = 0
              batch_size = batch_in.cont_shape[0]
              for sub_batch_in, sub_v in zip(
                  batch_in.cont_unstack_conts(0, keepdims=True),
                  v.cont_unstack_conts(0, keepdims=True),
              ):
                  cost = (
                      cost
                      - (
                          sub_batch_in["x"]
                          * sub_v["latent"]
                          * sub_v["weight"]
                      )[0]
                  )
              return cost / batch_size
  
          # outer cost function
          def outer_cost_fn(batch_in, v):
              cost = 0
              batch_size = batch_in.cont_shape[0]
              for sub_batch_in, sub_v in zip(
                  batch_in.cont_unstack_conts(0, keepdims=True),
                  v.cont_unstack_conts(0, keepdims=True),
              ):
                  cost = (
                      cost
                      + (
                          sub_batch_in["x"]
                          * sub_v["latent"]
                          * sub_v["weight"]
                      )[0]
                  )
              return cost / batch_size
  
          # numpy
          latent_np = ivy_backend.to_numpy(variables.latent[0:1])
          weight_np = ivy_backend.to_numpy(variables.weight[0:1])
          batch_np = batch.cont_map(
              lambda x, kc: ivy_backend.to_numpy(x)
          )
  
          # true gradient
          all_outer_grads = []
          for sub_batch in batch_np.cont_unstack_conts(
              0, True, num_tasks
          ):
              all_outer_grads.append(
                  [
                      (
                          -i
                          * inner_learning_rate
                          * weight_np
                          * sub_batch["x"][0] ** 2
                          - sub_batch["x"][0] * latent_np
                      )
                      * (-1 if with_outer_cost_fn else 1)
                      for i in range(inner_grad_steps + 1)
                  ]
              )
          if average_across_steps:
              true_weight_grad = (
                  sum(sum(og) / len(og) for og in all_outer_grads)
                  / num_tasks
              )
          else:
              true_weight_grad = (
                  sum(og[-1] for og in all_outer_grads) / num_tasks
              )
  
          # true latent gradient
          true_latent_grad = np.array(
              [
                  (-1 - (num_tasks - 1) / 2)
                  * (-1 if with_outer_cost_fn else 1)
              ]
          )
  
          # true cost
          true_cost_dict = {
              1: {
                  True: {
                      True: {1: 0.005, 2: 0.0125},
                      False: {1: 0.01, 2: 0.025},
                  },
                  False: {
                      True: {1: -0.005, 2: -0.0125},
                      False: {1: -0.01, 2: -0.025},
                  },
              },
              2: {
                  True: {
                      True: {1: 0.01, 2: 0.025},
                      False: {1: 0.02, 2: 0.05},
                  },
                  False: {
                      True: {1: -0.01, 2: -0.025},
                      False: {1: -0.02, 2: -0.05},
                  },
              },
              3: {
                  True: {
                      True: {1: 0.015, 2: 0.0375},
                      False: {1: 0.03, 2: 0.075},
                  },
                  False: {
                      True: {1: -0.015, 2: -0.0375},
                      False: {1: -0.03, 2: -0.075},
                  },
              },
          }
          true_cost = true_cost_dict[inner_grad_steps][
              with_outer_cost_fn
          ][average_across_steps][num_tasks]
  
          # meta update
          rets = ivy_backend.fomaml_step(
              batch,
              inner_cost_fn,
              outer_cost_fn if with_outer_cost_fn else None,
              variables,
              inner_grad_steps,
              inner_learning_rate,
              average_across_steps=average_across_steps,
              batched=batched,
              inner_v="latent",
              return_inner_v=return_inner_v,
              stop_gradients=stop_gradients,
          )
          calc_cost = rets[0]
          if stop_gradients:
              assert ivy_backend.equal(
                  ivy_backend.functional.ivy._is_variable(
                      calc_cost, exclusive=True
                  ),
                  False,
              )
          assert np.allclose(
              ivy_backend.to_scalar(calc_cost), true_cost
          )
          outer_grads = rets[1]
          assert np.allclose(
              ivy_backend.to_numpy(outer_grads.weight[0]),
              np.array(true_weight_grad),
          )
          assert np.allclose(
              ivy_backend.to_numpy(outer_grads.latent[0]),
              np.array(true_latent_grad),
          )
          if return_inner_v:
              inner_v_rets = rets[2]
              assert isinstance(inner_v_rets, ivy_backend.Container)
              if return_inner_v == "all":
                  assert list(inner_v_rets.cont_shape) == [num_tasks, 1]
              elif return_inner_v == "first":
                  assert list(inner_v_rets.cont_shape) == [1, 1]
  
file_path: ivy/ivy_tests/test_ivy/test_functional/test_core/test_meta.py
imports: import pytest
  import numpy
  from hypothesis import strategies
  import ivy_tests.test_ivy.helpers
  from ivy_tests.test_ivy.helpers import handle_test
  from ivy_tests.test_ivy.helpers.pipeline_helper import BackendHandler
label_desc: Use image node_id 1 for calling a global function with example usage: test_fomaml_step_overlapping_vars(on_device, inner_grad_steps, with_outer_cost_fn, average_across_steps, batched, stop_gradients, num_tasks, return_inner_v, backend_fw) and returns: unknown, unknown