-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add memory overhead to artifact description
- Loading branch information
1 parent
638bcd4
commit 4ce2673
Showing
6 changed files
with
103 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# sudo sh -c 'echo -1 >/proc/sys/kernel/perf_event_paranoid' | ||
# sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches' | ||
|
||
from time import time | ||
|
||
import torch | ||
from common.models import MODEL_CLASSES | ||
from linearcode.protection import PROTECTIONS | ||
from storage import get_storage_filename | ||
|
||
torch.random.manual_seed(0) | ||
imagenet_image = torch.rand((16, 3, 299, 299)) | ||
e2e_image = torch.rand((1, 3, 200, 66)) | ||
n = 256 | ||
|
||
|
||
def measure_time(input_image, _model): | ||
count = 10 | ||
start = time() | ||
for _ in range(count): | ||
_model.forward(input_image) | ||
return (time() - start) / count | ||
|
||
|
||
for protection in ( | ||
'sc', | ||
'milr', | ||
'radar', | ||
): | ||
detection_filename = get_storage_filename({'fig': 'detection_time_overhead', 'protection': protection}, | ||
extension='.tex', storage='../thesis/data/') | ||
|
||
with open(detection_filename, mode='w') as detection_file: | ||
for model_name, model_class in MODEL_CLASSES: | ||
if model_name in ('e2e', 'vgg19'): | ||
continue | ||
with torch.no_grad(): | ||
|
||
if model_name == 'e2e': | ||
image = e2e_image | ||
else: | ||
image = imagenet_image | ||
now = time() | ||
model = model_class(pretrained=True) | ||
print(time() - now) | ||
model = model | ||
image = image | ||
|
||
baseline_flops = measure_time(image, model) | ||
sc_normalized_model = PROTECTIONS['before_quantization'][protection](model, None) | ||
sc_detection_model = PROTECTIONS['after_quantization'][protection](sc_normalized_model, {'flips': 1, 'n': 2048}) | ||
sc_detection_flops = measure_time(image, sc_detection_model) | ||
|
||
print(model_name, | ||
100 * (sc_detection_flops / baseline_flops - 1), file=detection_file) | ||
detection_file.flush() | ||
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from common.models import MODEL_CLASSES | ||
from linearcode.protection import PROTECTIONS | ||
from storage import get_storage_filename | ||
|
||
memory_filename = get_storage_filename({'fig': 'memory_overhead', 'protection': 'sc'}, | ||
extension='.tex', storage='../thesis/data/') | ||
|
||
with open(memory_filename, mode='w') as memory_file: | ||
for model_name, model_class in MODEL_CLASSES: | ||
if model_name in ('e2e', 'vgg19'): | ||
continue | ||
model = model_class() | ||
normalized_model = PROTECTIONS['before_quantization']['sc'](model, None) | ||
sc_correction_model = PROTECTIONS['after_quantization']['sc'](normalized_model, {'flips': 32}) | ||
correction_size = sum(p.nelement() for p in sc_correction_model.parameters()) | ||
model_size = sum(p.nelement() for p in model.parameters()) | ||
print(model_name, round(100 * (correction_size / model_size - 1), 2), file=memory_file) | ||
|
||
memory_filename = get_storage_filename({'fig': 'memory_overhead', 'protection': 'milr'}, | ||
extension='.tex', storage='../thesis/data/') | ||
|
||
with open(memory_filename, mode='w') as memory_file: | ||
for model_name, model_class in MODEL_CLASSES: | ||
if model_name in ('e2e', 'vgg19'): | ||
continue | ||
model = model_class() | ||
normalized_model = PROTECTIONS['before_quantization']['milr'](model, None) | ||
sc_correction_model = PROTECTIONS['after_quantization']['milr'](normalized_model, {'flips': 32}) | ||
model_size = sum(p.nelement() for p in model.parameters()) | ||
correction_size = sum( | ||
m.checkpoint.nelement() for m in sc_correction_model.modules() if hasattr(m, 'checkpoint')) + model_size | ||
print(model_name, round(100 * (correction_size / model_size - 1), 2), file=memory_file) | ||
|
||
memory_filename = get_storage_filename({'fig': 'memory_overhead', 'protection': 'radar'}, | ||
extension='.tex', storage='../thesis/data/') | ||
with open(memory_filename, mode='w') as memory_file: | ||
for model_name, model_class in MODEL_CLASSES: | ||
if model_name in ('e2e', 'vgg19'): | ||
continue | ||
print(model_name, 25, file=memory_file) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
galois==0.0.24 | ||
torchvision==0.9.0 | ||
torchvision==0.10.1 | ||
matplotlib==3.5.1 |