Skip to content

Commit

Permalink
removed simple
Browse files Browse the repository at this point in the history
  • Loading branch information
joannapng committed Jun 29, 2024
1 parent 59fe060 commit e374788
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 104 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path to model (should be inside checkpoints folder ending in _best.tar)> --freq 300 --target-fps 6000 --board U250 --num-episodes 30
mkdir resnet18
python train.py --model-name resnet18 --dataset CIFAR10 --model-path <path to model (should be inside checkpoints folder ending in _best.tar)> --freq 200 --target-fps 400 --board U250 --num-episodes 200
```
## Step 6: Test agent on LeNet5
```
Expand Down
51 changes: 0 additions & 51 deletions exporter/Exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
50 changes: 1 addition & 49 deletions train/exporter/Exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 1 addition & 3 deletions train/finetune/Finetuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit e374788

Please sign in to comment.