class_docstr: Scope to prevent any update to Keras Variables.
  
  The values of variables to be used inside the scope
  should be passed via the `state_mapping` argument, a
  list of tuples `(k, v)` where `k` is a `KerasVariable`
  and `v` is the intended value for this variable
  (a backend tensor).
  
  Updated values can be collected on scope exit via
  `value = scope.get_current_value(variable)`. No updates
  will be applied in-place to any variables for the duration
  of the scope.
  
  Example:
  
  ```python
  state_mapping = [(k, ops.ones(k.shape, k.dtype)) for k in model.weights]
  with keras.StatelessScope(state_mapping) as scope:
      outputs = model.some_function(inputs)
  
  # All model variables remain unchanged. Their new values can be
  # collected via:
  for k in model.weights:
      new_value = scope.get_current_value(k)
      print(f"New value for {k}: {new_value})
  ```
code: def __init__(
      self,
      state_mapping=None,
      collect_losses=False,
      initialize_variables=True,
  ):
      from keras import backend
      from keras.backend.common.variables import KerasVariable
  
      self.collect_losses = collect_losses
      self.initialize_variables = initialize_variables
      self.losses = []
      self.state_mapping = {}
      state_mapping = state_mapping or {}
      for k, v in state_mapping:
          if not isinstance(k, KerasVariable):
              raise ValueError(
                  "Invalid reference variable in StatelessScope: "
                  "all keys in argument `mapping` must be KerasVariable "
                  f"instances. Received instead: {k}"
              )
          v = backend.convert_to_tensor(v, dtype=k.dtype)
          if k.shape != v.shape:
              raise ValueError(
                  "Invalid variable value in StatelessScope: "
                  "all values in argument `mapping` must be tensors with "
                  "a shape that matches the corresponding variable shape. "
                  f"For variable {k}, received invalid value {v} with shape "
                  f"{v.shape}."
              )
          self.state_mapping[id(k)] = v
  
file_path: keras/keras/backend/common/stateless_scope.py
imports: from keras.api_export import keras_export
  from keras.backend.common import global_state
label_desc: Use image node_id 1 to create a new StatelessScope object  with example: obj = StatelessScope(state_mapping, collect_losses, initialize_variables)