def test_wandb_log_model_with_score(wandb_mock, tmp_path):
    """Test to prevent regression on #15543, ensuring the score is logged as a Python number, not a scalar tensor."""
    wandb_mock.run = None
    model = BoringModel()

    wandb_mock.init().log_artifact.reset_mock()
    wandb_mock.init.reset_mock()
    wandb_mock.Artifact.reset_mock()
    logger = WandbLogger(save_dir=tmp_path, log_model=True)
    logger.experiment.id = "1"
    logger.experiment.name = "run_name"
    checkpoint_callback = ModelCheckpoint(monitor="step")
    trainer = Trainer(
        default_root_dir=tmp_path,
        logger=logger,
        callbacks=[checkpoint_callback],
        max_epochs=1,
        limit_train_batches=3,
        limit_val_batches=1,
    )
    trainer.fit(model)

    calls = wandb_mock.Artifact.call_args_list
    assert len(calls) == 1
    score = calls[0][1]["metadata"]["score"]
    # model checkpoint monitors scalar tensors, but wandb can't serializable them - expect Python scalars in metadata
    assert isinstance(score, int)
    assert score == 3
Test to prevent regression on #15543, ensuring the score is logged as a Python number, not a scalar tensor.
tests/tests_pytorch/loggers/test_wandb.py