Example #1
0
    def test_recipe_seed(self, dataset_name, model_name, init_schema,
                         optimizer_name, tmp_path):
        experiment_dir = tmp_path / 'experiment'
        experiment = Experiment(directory=experiment_dir)

        initial_state = experiment.spawn_new_tree(
            dataset_name=dataset_name,
            model_name=model_name,
            init_schema=init_schema,
            optimizer_name=optimizer_name,
            seed=999,
        )
        assert initial_state.get().seed == 999

        r = Recipe(train={"n_epochs": 1})
        assert r.seed is None

        new_state = r(initial_state)
        assert r.seed == initial_state.get().seed
Example #2
0
logger = logging.getLogger("main")
utils.setup_logging(debug=True)

directory = "../output/08-06-19_seed1"
experiment = Experiment(directory=directory)

# this materializes immediately
x = experiment.spawn_new_tree(
    dataset_name="mnist",
    model_name="models.LeNet",
    init_schema="",
    optimizer_name="sgd",
    seed=1,
)

x = Recipe(train={"n_epochs": 30})(x)

for _ in range(20):
    # finetune
    pruned = Recipe(
        prune_schema="../schemas/pruning_schema_lenet_structuredrandom.py", )(
            x)
    x = Recipe(
        reinit_schema="../schemas/reinit_schema_lt_lenet.py",
        train={"n_epochs": 30},
    )(pruned)  # LT

    # x = Recipe(
    #     train={"n_epochs": 20},
    # )(pruned) # finetuning
logger = logging.getLogger("main")
utils.setup_logging(debug=True)

directory = "../output/vgg11_cifar10_seed4"
experiment = Experiment(directory=directory)

# this materializes immediately
x = experiment.spawn_new_tree(
    dataset_name="cifar-10",
    model_name="torchvision.models.vgg11",
    init_schema="",
    optimizer_name="sgd",
    seed=4,
)

x = Recipe(train={"n_epochs": 30})(x)

for _ in range(20):
    # finetune
    pruned = Recipe(
        prune_schema="../schemas/pruning_schema_vgg11_unstructuredl1.py", )(x)
    x = Recipe(
        reinit_schema="../schemas/reinit_schema_lt_vgg11.py",
        train={"n_epochs": 30},
    )(pruned)  # LT

    # x = Recipe(
    #     train={"n_epochs": 20},
    # )(pruned) # finetuning

experiment.run()
Example #4
0
import os
import utils

logger = logging.getLogger("main")
utils.setup_logging(debug=True)

directory = "../output/08-06-19_seed3"
experiment = Experiment(directory=directory)

# this materializes immediately
x = experiment.spawn_new_tree(
    dataset_name="mnist",
    model_name="models.LeNet",
    init_schema="",
    optimizer_name="sgd",
    seed=3,
)

x = Recipe(train={"n_epochs": 30})(x)

for _ in range(20):
    pruned = Recipe(
        prune_schema="../schemas/pruning_schema_lenet_unstructuredl1.py", )(x)
    # x = Recipe(
    #     reinit_schema="../schemas/reinit_schema_lt_lenet.py",
    #     train={"n_epochs": 30},
    # )(pruned) # LT

    x = Recipe(train={"n_epochs": 30}, )(pruned)  # finetuning

experiment.run()
# This materializes immediately
initial_state = experiment.spawn_new_tree(
    dataset_name="mnist",
    model_name="models.LeNet",
    init_schema="schemas/init_kaiminguniform_lenet.py",
    optimizer_name="sgd",
    seed=0,
    device=torch.device("cpu"),
)

# These are computed lazily until .run() is called. A Recipe represents a
# way to transition from one state (read: model) to the following via
# pruning, finetuning, and reinitializing
state1 = Recipe(
    train={"n_epochs": 1},
    prune_schema="schemas/pruning_schema_lenet_unstructuredl1.py",
)(initial_state)

state2 = Recipe(reinit_schema="schemas/reinit_schema_lenet.py")(state1)

state3 = Recipe(
    train={"n_epochs": 1},
    prune_schema="schemas/pruning_schema_lenet_unstructuredl1.py",
    reinit_schema="schemas/reinit_schema_lenet.py",
)(state2)

final_state = Recipe(train={"n_epochs": 1})(state3)

# When .run() is called, we execute the full experiment graph
experiment.run()
logger = logging.getLogger("main")
utils.setup_logging(debug=True)

directory = "../output/alexnet_seed4"
experiment = Experiment(directory=directory)

# this materializes immediately
x = experiment.spawn_new_tree(
    dataset_name="mnist",
    model_name="torchvision.models.AlexNet",
    init_schema="",
    optimizer_name="sgd",
    seed=4,
)

x = Recipe(train={"n_epochs": 30})(x)

for _ in range(20):
    # finetune
    pruned = Recipe(
        prune_schema="../schemas/pruning_schema_alexnet_mixedl1.py", )(x)
    x = Recipe(
        reinit_schema="../schemas/reinit_schema_lt_alexnet.py",
        train={"n_epochs": 30},
    )(pruned)  # LT

    # x = Recipe(
    #     train={"n_epochs": 20},
    # )(pruned) # finetuning

experiment.run()
Example #7
0
utils.setup_logging(debug=True)

directory = "../output/lenet1ep_seed4" #"../output/08-06-19_seed0"
experiment = Experiment(directory=directory)

# this materializes immediately
x = experiment.spawn_new_tree(
    dataset_name="mnist",
    model_name="models.LeNet",
    init_schema="",
    optimizer_name="sgd",
    seed=4,
)

x = Recipe(
    train={"n_epochs": 1} # 30
)(x)

# new 
y = Recipe(
    train={"n_epochs": 29}
)(x)

for _ in range(20):
    # finetune
    pruned = Recipe(
        prune_schema="../schemas/pruning_schema_lenet_unstructuredl1.py",
    )(x)
    x = Recipe(
        reinit_schema="../schemas/reinit_schema_lt_lenet.py",
        train={"n_epochs": 1}, # 30
Example #8
0
utils.setup_logging(debug=True)

directory = "../output/08-06-19_seed4"
experiment = Experiment(directory=directory)

# this materializes immediately
x = experiment.spawn_new_tree(
    dataset_name="mnist",
    model_name="models.LeNet",
    init_schema="",
    optimizer_name="sgd",
    seed=4,
)

x = Recipe(
    train={"n_epochs": 30}
)(x)

for _ in range(10):
    # finetune
    pruned = Recipe(
    	prune_schema="../schemas/pruning_schema_lenet_unstructuredl1.py",
        name='halfhalfR',
    )(x)
    x = Recipe(
        reinit_schema="../schemas/reinit_schema_lt_lenet.py",
        train={"n_epochs": 30},
        name='halfhalfR',
    )(pruned)

for _ in range(10):