-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ADC and Variable Input Voltage Range Support, and Modularized A…
…ll memtorch.mn Modules (#30)
- Loading branch information
1 parent
6496cb3
commit a0d82ce
Showing
23 changed files
with
357 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "memtorch/submodules/pytorch-playground"] | ||
path = memtorch/submodules/pytorch-playground | ||
url = https://github.com/coreylammie/pytorch-playground |
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
Binary file not shown.
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,10 @@ | ||
coverage: | ||
status: | ||
project: | ||
default: | ||
target: 90% | ||
threshold: 0.5% | ||
patch: | ||
default: | ||
target: 85% | ||
threshold: 0.5% |
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,50 @@ | ||
# Wrapper for the pytorch-playground quant.py script | ||
import importlib | ||
utee = importlib.import_module('.utee', 'memtorch.submodules.pytorch-playground') | ||
import torch | ||
import numpy as np | ||
quant_methods = ['linear', 'log', 'tanh'] | ||
|
||
def quantize(input, bits, overflow_rate, quant_method='linear', min=None, max=None): | ||
"""Method to quantize a tensor. | ||
Parameters | ||
---------- | ||
input : tensor | ||
Input tensor. | ||
bits : int | ||
Bit width. | ||
overflow_rate : float | ||
Overflow rate threshold for linear quanitzation. | ||
quant_method : str | ||
Quantization method. Must be in ['linear', 'log', 'tanh']. | ||
min : float | ||
Minimum value to clip values to. | ||
max : float | ||
Maximum value to clip values to. | ||
Returns | ||
------- | ||
tensor | ||
Quantized tensor. | ||
""" | ||
assert type(bits) == int and bits > 0, 'bits must be an integer > 0.' | ||
assert overflow_rate >= 0 and overflow_rate <= 1, 'overflow_rate value invalid.' | ||
assert quant_method in quant_methods, 'quant_method is not valid.' | ||
if min is not None: | ||
input = input.clip(min=min) | ||
|
||
if max is not None: | ||
input = input.clip(max=max) | ||
|
||
if quant_method == 'linear': | ||
sf = bits - 1 - utee.compute_integral_part(input, overflow_rate) | ||
return utee.linear_quantize(input, sf, bits) | ||
elif quant_method == 'log': | ||
log_abs_input = torch.log(torch.abs(input)) | ||
log_abs_input[log_abs_input == float('-inf')] = 1e-12 | ||
sf = bits - 1 - utee.compute_integral_part(log_abs_input, overflow_rate) | ||
return utee.log_linear_quantize(input, sf, bits) | ||
elif quant_method == 'tanh': | ||
return utee.tanh_quantize(input, bits) |
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,4 @@ | ||
from .memristor import * | ||
from .crossbar import * | ||
from .StochasticParameter import * | ||
from .Quantize import * |
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
Oops, something went wrong.