This file contains hidden or 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
class AdamStepLR(torch.optim.Adam): | |
"""Combine Adam and lr_scheduler.StepLR so we can use it as a normal optimiser""" | |
def __init__(self, params, lr=0.001, betas=(0.9, 0.999), eps=1e-08, weight_decay=0, step_size=50000, gamma=0.5): | |
super().__init__(params, lr, betas, eps, weight_decay) | |
self.scheduler = torch.optim.lr_scheduler.StepLR(self, step_size, gamma) | |
def step(self): | |
self.scheduler.step() | |
return super().step() |
This file contains hidden or 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
""" | |
In jupyter notebook simple logging to console | |
""" | |
import logging | |
import sys | |
logging.basicConfig(stream=sys.stdout, level=logging.INFO) | |
# Test | |
logger = logging.getLogger('LOGGER_NAME') |
This file contains hidden or 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
from dask.callbacks import Callback | |
from tqdm.auto import tqdm | |
class TQDMDaskProgressBar(Callback, object): | |
""" | |
A tqdm progress bar for dask. | |
Usage: | |
``` | |
with TQDMDaskProgressBar(): |
This file contains hidden or 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
import torch.utils.data | |
class NumpyDataset(torch.utils.data.Dataset): | |
"""Dataset wrapping arrays. | |
Each sample will be retrieved by indexing array along the first dimension. | |
Arguments: | |
*arrays (numpy.array): arrays that have the same size of the first dimension. |
This file contains hidden or 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
""" | |
Pytorch sampler that samples ordered indices from unordered sequences. | |
Good for use with dask and RNN's, because | |
1. Dask will slow down if sampling between chunks, so we must do one chunk at a time | |
2. RNN's need sequences so we must have seqences e.g. 1,2,3 | |
3. But RNN's train better with batches that are uncorrelated so we want each batch to be sequence from a different part of a chunk. | |
For example, given each chunk is `range(12)`. Our seq_len is 3. We might end up with these indices: | |
- [[1,2,3],[9,10,11],[4,5,6]] |
This file contains hidden or 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
def isfinite(x): | |
""" | |
Quick pytorch test that there are no nan's or infs. | |
note: torch now has torch.isnan | |
url: https://gist.github.com/wassname/df8bc03e60f81ff081e1895aabe1f519 | |
""" | |
not_inf = ((x + 1) != x) | |
not_nan = (x == x) | |
return not_inf & not_nan |
This file contains hidden or 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
from torch.nn.modules.utils import _pair | |
class CausalConv2d(nn.Conv2d): | |
def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=None, dilation=1, groups=1, bias=True): | |
kernel_size = _pair(kernel_size) | |
stride = _pair(stride) | |
dilation = _pair(dilation) | |
if padding is None: | |
padding = [int((kernel_size[i] -1) * dilation[i]) for i in range(len(kernel_size))] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This are a collection of fixes and tweaks I used to get Xubuntu 18.04 LTS working on a lenovo thinkpad X380 yoga laptop.
-
Bios:
- First UPDATE IT, since some old bioses may cause bricking when settings are changed. I used 1.22 and it was fine, but it's no garuntee for others.
- you can use linux or the preinstalled windows to update the bios http://positon.org/lenovo-thinkpad-bios-update-with-linux-and-usb
- put into legacy mode (not UEFI) before install, to allow undervolting (to save power and heat)
- 'Security -> Secure Boot - Set to "Disabled"'
- (optional) turn off hyperthreading if you want to save more power
- First UPDATE IT, since some old bioses may cause bricking when settings are changed. I used 1.22 and it was fine, but it's no garuntee for others.
-
(optional) find the settings for cpu power management and switch to power saving or balanced mode on battery (if not already)