keras/src/metrics/metric.py/Metric/add_variable
class Metric:    def add_variable(
        self, shape, initializer, dtype=None, aggregation="sum", name=None
    ):
        self._check_super_called()
        with backend.name_scope(self.name.replace("/", ">"), caller=self):
            initializer = initializers.get(initializer)
            variable = backend.Variable(
                initializer=initializer,
                shape=shape,
                dtype=dtype,
                trainable=False,
                aggregation=aggregation,
                name=name,
            )
        # Prevent double-tracking
        self._tracker.add_to_store("variables", variable)
        return variable