diff --git a/README.md b/README.md index ef17c0e..5bf6a16 100644 --- a/README.md +++ b/README.md @@ -21,15 +21,19 @@ bash run-docker.sh cd Thesis ``` -## Step 4: Pretrain LeNet5 on MNIST +## Step 4: Pretrain LeNet5 on MNIST / ResNet18 on CIFAR10 ``` python pretrain.py --model-name LeNet5 --dataset MNIST --training-epochs 10 +python pretrain.py --model-name resnet18 --dataset CIFAR10 --training-epochs 30 ``` ## Step 5: Train agent on LeNet5 ``` mkdir LeNet5 python train.py --model-name LeNet5 --dataset MNIST --model-path --freq 300 --target-fps 6000 --board U250 --num-episodes 30 + +mkdir resnet18 +python train.py --model-name resnet18 --dataset CIFAR10 --model-path --freq 200 --target-fps 400 --board U250 --num-episodes 200 ``` ## Step 6: Test agent on LeNet5 ``` diff --git a/exporter/Exporter.py b/exporter/Exporter.py index b26f2fd..17b53ce 100644 --- a/exporter/Exporter.py +++ b/exporter/Exporter.py @@ -228,29 +228,6 @@ def streamline_lenet(model: ModelWrapper, cfg: build.DataflowBuildConfig): return model -def streamline_simple(model: ModelWrapper, cfg: build.DataflowBuildConfig): - model = model.transform(ConvertSubToAdd()) - model = model.transform(ConvertDivToMul()) - - model = model.transform(collapse.CollapseRepeatedMul()) - model = model.transform(absorb.AbsorbMulIntoMultiThreshold()) - model = model.transform(absorb.AbsorbSignBiasIntoMultiThreshold()) - model = model.transform(absorb.AbsorbAddIntoMultiThreshold()) - - model = model.transform(reorder.MoveScalarMulPastConv()) - model = model.transform(absorb.AbsorbMulIntoMultiThreshold()) - model = model.transform(collapse.CollapseRepeatedMul()) - model = model.transform(reorder.MoveMulPastMaxPool()) - model = model.transform(reorder.MoveScalarLinearPastInvariants()) - model = model.transform(reorder.MoveScalarMulPastMatMul()) - model = model.transform(absorb.AbsorbMulIntoMultiThreshold()) - model = model.transform(absorb.AbsorbScalarMulAddIntoTopK()) - - if VerificationStepType.STREAMLINED_PYTHON in cfg._resolve_verification_steps(): - verify_step(model, cfg, "streamlined_python", need_parent=False) - - - return model def streamline_resnet(model: ModelWrapper, cfg: build.DataflowBuildConfig): model = model.transform(ConvertSubToAdd()) @@ -330,34 +307,6 @@ def convert_to_hw_resnet(model: ModelWrapper, cfg: build.DataflowBuildConfig): return model -def convert_to_hw_simple(model: ModelWrapper, cfg: build.DataflowBuildConfig): - model = model.transform(InferDataLayouts()) - model = model.transform(convert.InferPool()) - - model = model.transform(LowerConvsToMatMul()) - model = model.transform(convert.InferConvInpGen()) - model = model.transform(convert.InferVectorVectorActivation()) - model = model.transform(convert.InferBinaryMatrixVectorActivation()) - model = model.transform(convert.InferQuantizedMatrixVectorActivation()) - - model = model.transform(absorb.AbsorbAddIntoMultiThreshold()) - model = model.transform(absorb.AbsorbTransposeIntoMultiThreshold()) - model = model.transform(absorb.AbsorbConsecutiveTransposes()) - - model = model.transform(InferDataLayouts()) - model = model.transform(convert.InferThresholdingLayer()) - - model = model.transform(InferDataLayouts()) - model = model.transform(convert.InferLabelSelectLayer()) - - model = model.transform(InferDataLayouts()) - model = model.transform(RemoveCNVtoFCFlatten()) - - model = model.transform(RoundAndClipThresholds()) - model = tidy_up(model) - - return model - def convert_to_hw_lenet(model: ModelWrapper, cfg: build.DataflowBuildConfig): model = model.transform(InferDataLayouts()) model = model.transform(convert.InferPool()) diff --git a/train/exporter/Exporter.py b/train/exporter/Exporter.py index f46f8cd..276f94b 100644 --- a/train/exporter/Exporter.py +++ b/train/exporter/Exporter.py @@ -230,26 +230,6 @@ def streamline_lenet(model): return model -def streamline_simple(model): - model = model.transform(ConvertSubToAdd()) - model = model.transform(ConvertDivToMul()) - - model = model.transform(collapse.CollapseRepeatedMul()) - model = model.transform(absorb.AbsorbMulIntoMultiThreshold()) - model = model.transform(absorb.AbsorbSignBiasIntoMultiThreshold()) - model = model.transform(absorb.AbsorbAddIntoMultiThreshold()) - - model = model.transform(reorder.MoveScalarMulPastConv()) - model = model.transform(absorb.AbsorbMulIntoMultiThreshold()) - model = model.transform(collapse.CollapseRepeatedMul()) - model = model.transform(reorder.MoveMulPastMaxPool()) - model = model.transform(reorder.MoveScalarLinearPastInvariants()) - model = model.transform(reorder.MoveScalarMulPastMatMul()) - model = model.transform(absorb.AbsorbMulIntoMultiThreshold()) - model = model.transform(absorb.AbsorbScalarMulAddIntoTopK()) - - return model - def streamline_resnet(model): model = model.transform(ConvertSubToAdd()) model = model.transform(ConvertDivToMul()) @@ -347,35 +327,7 @@ def convert_to_hw_lenet(model): model = tidy_up(model) return model - -def convert_to_hw_simple(model): - model = model.transform(InferDataLayouts()) - model = model.transform(convert.InferPool()) - - model = model.transform(LowerConvsToMatMul()) - model = model.transform(convert.InferConvInpGen()) - model = model.transform(convert.InferVectorVectorActivation()) - model = model.transform(convert.InferBinaryMatrixVectorActivation()) - model = model.transform(convert.InferQuantizedMatrixVectorActivation()) - - model = model.transform(absorb.AbsorbAddIntoMultiThreshold()) - model = model.transform(absorb.AbsorbTransposeIntoMultiThreshold()) - model = model.transform(absorb.AbsorbConsecutiveTransposes()) - - model = model.transform(InferDataLayouts()) - model = model.transform(convert.InferThresholdingLayer()) - - model = model.transform(InferDataLayouts()) - model = model.transform(convert.InferLabelSelectLayer()) - - model = model.transform(InferDataLayouts()) - model = model.transform(RemoveCNVtoFCFlatten()) - - model = model.transform(RoundAndClipThresholds()) - model = tidy_up(model) - - return model - + def name_nodes(model): model = model.transform(GiveUniqueNodeNames()) model = model.transform(GiveReadableTensorNames()) diff --git a/train/finetune/Finetuner.py b/train/finetune/Finetuner.py index 6dc6a7f..6769729 100644 --- a/train/finetune/Finetuner.py +++ b/train/finetune/Finetuner.py @@ -14,15 +14,13 @@ from .calibrate import calibrate from pretrain.models.LeNet5 import LeNet5 from pretrain.models.resnet import ResNet18, ResNet34, ResNet50, ResNet101, ResNet152 -from pretrain.models.Simple import Simple networks = {'LeNet5' : LeNet5, 'resnet18' : ResNet18, 'resnet34' : ResNet34, 'resnet50' : ResNet50, 'resnet101' : ResNet101, - 'resnet152' : ResNet152, - 'Simple' : Simple} + 'resnet152' : ResNet152} class Finetuner(object): def __init__(self, args, model_config):