Skip to content

Dummy Algorithm

The Dummy Algorithm is a simple algorithm that does not perform any fusion operation. Instead, it returns a pretrained model if one is available in the model pool. If no pretrained model is available, it returns the first model in the model pool. This algorithm is useful for testing and debugging purposes, as it allows you to quickly check if the model pool is set up correctly and the fusion process is working as expected.

Usage

To use the Dummy Algorithm, you need to specify "dummy" as the algorithm name.

fusion_bench method=dummy ...

Implementation

The implementation of the Dummy Algorithm is straightforward. Here is the main method of the DummyAlgorithm class:

DummyAlgorithm

Bases: ModelFusionAlgorithm

Source code in fusion_bench/method/dummy.py
class DummyAlgorithm(ModelFusionAlgorithm):
    def __init__(self, algorithm_config: DictConfig):
        super().__init__(algorithm_config)

    def run(self, modelpool: ModelPool):
        """
        This method returns the pretrained model from the model pool.
        If the pretrained model is not available, it returns the first model from the model pool.

        Raises:
            AssertionError: If the model is not found in the model pool.
        """
        modelpool = to_modelpool(modelpool)
        if "_pretrained_" in modelpool._model_names:
            model = modelpool.load_model("_pretrained_")
        else:
            log.warning(
                "No pretrained model found in the model pool. Returning the first model."
            )
            model = modelpool.load_model(modelpool.model_names[0])

        assert model is not None, "Model is not found in the model pool."
        return model