def test_activation_checkpointing_does_not_change_metrics(self):
        """--checkpoint-activations should not change loss"""
        base_flags = [
            "--encoder-layers",
            "2",
            "--decoder-layers",
            "2",
            "--encoder-embed-dim",
            "8",
            "--decoder-embed-dim",
            "8",
            "--restore-file",
            "x.pt",
            "--log-format",
            "json",
            "--log-interval",
            "1",
            "--max-update",
            "2",
        ]

        def _train(extra_flags):
            with self.assertLogs() as logs:
                train_translation_model(
                    data_dir,
                    "transformer_iwslt_de_en",
                    base_flags + extra_flags,
                    run_validation=True,
                    extra_valid_flags=["--log-format", "json"],
                )
            return logs.records

        with tempfile.TemporaryDirectory("test_transformer_with_act_cpt") as data_dir:

            create_dummy_data(data_dir, num_examples=20)
            preprocess_translation_data(data_dir)
            ckpt_logs = _train(["--checkpoint-activations"])
            baseline_logs = _train([])
            assert len(baseline_logs) == len(ckpt_logs)

            baseline_train_stats = read_last_log_entry(baseline_logs, "train")
            ckpt_train_stats = read_last_log_entry(ckpt_logs, "train")
            assert baseline_train_stats["train_loss"] == ckpt_train_stats["train_loss"]

            baseline_valid_stats = read_last_log_entry(baseline_logs, "valid")
            ckpt_valid_stats = read_last_log_entry(ckpt_logs, "valid")
            assert baseline_valid_stats["valid_loss"] == ckpt_valid_stats["valid_loss"]
--checkpoint-activations should not change loss
decoding/IAD/fairseq/tests/test_binaries.py