def scalar_v2_mock(name, data, step=None):
            """A reimplementation of the scalar plugin to avoid circular
            deps."""
            metadata = SummaryMetadata()
            # Should match value in tensorboard/plugins/scalar/metadata.py.
            metadata.plugin_data.plugin_name = "scalars"
            with summary.experimental.summary_scope(
                name, "scalar_summary", values=[data, step]
            ) as (tag, _):
                tensor = backend.convert_to_tensor(data, dtype="float32")
                if backend.backend() == "torch":
                    # TODO: Use device scope after the API is added.
                    if tensor.is_cuda:
                        tensor = tensor.cpu()
                summary.write(
                    tag=tag,
                    tensor=tensor,
                    step=step,
                    metadata=metadata,
                )
A reimplementation of the scalar plugin to avoid circular
            deps.
keras/src/callbacks/tensorboard_test.py