From fa7c54a5a04b9c06bfc3a01bb26cf2322c13b067 Mon Sep 17 00:00:00 2001 From: Alin Gavriliuc Date: Wed, 12 Apr 2023 17:21:11 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20=20Homebrew=20cheatsheet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/_posts/homebrew.md | 176 ++++++++++++++++++++++++++++++++ source/assets/icon/homebrew.svg | 27 +++++ 2 files changed, 203 insertions(+) create mode 100644 source/_posts/homebrew.md create mode 100644 source/assets/icon/homebrew.svg diff --git a/source/_posts/homebrew.md b/source/_posts/homebrew.md new file mode 100644 index 0000000..8014dc4 --- /dev/null +++ b/source/_posts/homebrew.md @@ -0,0 +1,176 @@ +--- +title: Homebrew +date: 2023-04-12 +background: bg-[#fbb041] +tags: + - packages manager + - macos +categories: + - Toolkit +intro: This is a quick reference cheat sheet to getting started with linux bash shell scripting. +plugins: + - copyCode +--- + +## Getting Started + +### Install + +If not installed, instll Command Line Tools (CTL) + +``` +xcode-select --install +``` + +Install Homebrew : + +``` +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +``` + +### Commands + +| | | +|----------------------------------|----------------------------------------| +| ``` brew install git ``` | Install a package | +| ``` brew uninstall git ``` | Uninstall a package | +| ``` brew upgrade git ``` | Upgrade package | +| ``` brew unlink git ``` | Unlink | +| ``` brew link git ``` | Link | +| ``` brew switch git 1.0.0 ``` | Switch package version | +| ``` brew list --versions git ``` | List the installed versions of package | + + +### Help + +Display the version of Homebrew. +```` +brew --version +```` +Print Help Information +```` +brew help +```` +Print Help Info for a brew command +```` +brew help +```` +Check system for potential problems. +```` +brew doctor +```` + +### Updates + +Fetch latest version of homebrew and formula +``` +brew update +``` +Show formulae with an updated version available +``` +brew outdated +``` +Upgrade all outdated and unpinned brews +``` +brew upgrade +``` +Upgrade only the specified brew +``` +brew upgrade +``` +Prevent the specified formulae from being upgraded +``` +brew pin +``` +Allow the specified formulae to be upgraded. +``` +brew unpin +``` + +### Repositories + +List all the current tapped repositories (taps) +``` +brew tap +``` +Tap a formula repository from Github using https for tap https://github.com/user/homebrew-repo +``` +brew tap +``` +Tap a formula repository from the specified URL +``` +brew tap +``` +Remove the given tap from the repository +``` +brew untap +``` + +### Cask + +Tap the Cask repository from Github. +``` +brew tap homebrew/cask +``` +List all the installed casks . +``` +brew cask list +``` +Search all known casks based on the substring text. +``` +brew search +``` +Install the given cask. +``` +brew cask install +``` +Reinstalls the given Cask +``` +brew cask reinstall +``` +Uninstall the given cask. +``` +brew cask uninstall +``` + +### Search, Install, Remove + +List all the installed formulae. +``` +brew list +``` +Display all locally available formulae for brewing. +``` +brew search +``` +Perform a substring search of formulae names for brewing. +``` +brew search +``` +Display information about the formula. +``` +brew info +``` +Install the formula. +``` +brew install +``` +Uninstall the formula. +``` +brew uninstall +``` + +### Cleanup + +Remove older versions of installed formulae. +``` +brew cleanup +``` +Remove older versions of specified formula. +``` +brew cleanup +``` +Display all formula that will be removed (dry run) +``` +brew cleanup -n +``` \ No newline at end of file diff --git a/source/assets/icon/homebrew.svg b/source/assets/icon/homebrew.svg new file mode 100644 index 0000000..3e93075 --- /dev/null +++ b/source/assets/icon/homebrew.svg @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 1409d5f1df04f6508d0e341c4dd2bc6b7486136e Mon Sep 17 00:00:00 2001 From: Alin Gavriliuc Date: Wed, 12 Apr 2023 23:03:59 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20=20fixed=20intro=20typ?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/_posts/homebrew.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/_posts/homebrew.md b/source/_posts/homebrew.md index 8014dc4..d44b085 100644 --- a/source/_posts/homebrew.md +++ b/source/_posts/homebrew.md @@ -7,7 +7,7 @@ tags: - macos categories: - Toolkit -intro: This is a quick reference cheat sheet to getting started with linux bash shell scripting. +intro: This is a quick reference cheat sheet to getting started with homebrew. plugins: - copyCode --- From f49f04bd6dfa13a666d1091c2b02984ed63f6021 Mon Sep 17 00:00:00 2001 From: Alin Gavriliuc Date: Wed, 12 Apr 2023 23:20:48 +0200 Subject: [PATCH 3/3] PyTorch cheatsheet --- source/_posts/pytorch.md | 223 +++++++++++++++++++++++++++++++++ source/assets/icon/pytorch.svg | 2 + 2 files changed, 225 insertions(+) create mode 100644 source/_posts/pytorch.md create mode 100644 source/assets/icon/pytorch.svg diff --git a/source/_posts/pytorch.md b/source/_posts/pytorch.md new file mode 100644 index 0000000..fac0124 --- /dev/null +++ b/source/_posts/pytorch.md @@ -0,0 +1,223 @@ +--- +title: PyTorch +date: 2023-04-12 +background: bg-[#ee4c2c] +tags: + - AI + - Python +categories: + - Other +intro: This is a quick reference list of cheat sheets for PyTorch. See also [PyTorch website](https://pytorch.org/) +--- + +## Imports { .cols-1 } + +### General + +``` +import torch # root package +from torch.utils.data import Dataset, DataLoader # dataset representation and loading +``` + +### Neural Network API + +``` +import torch.autograd as autograd # computation graph +from torch import Tensor # tensor node in the computation graph +import torch.nn as nn # neural networks +import torch.nn.functional as F # layers, activations and more +import torch.optim as optim # optimizers e.g. gradient descent, ADAM, etc. +from torch.jit import script, trace # hybrid frontend decorator and tracing jit +``` + +### Torchscript and JIT + +``` +torch.jit.trace() # takes your module or function and an example + # data input, and traces the computational steps + # that the data encounters as it progresses through the model + +@script # decorator used to indicate data-dependent + # control flow within the code being traced +``` + +### ONNX + +``` +torch.onnx.export(model, dummy data, xxxx.proto) # exports an ONNX formatted + # model using a trained model, dummy + # data and the desired file name + +model = onnx.load("alexnet.proto") # load an ONNX model +onnx.checker.check_model(model) # check that the model + # IR is well formed + +onnx.helper.printable_graph(model.graph) # print a human readable + # representation of the graph +``` + +### Vision + + +``` +from torchvision import datasets, models, transforms # vision datasets, + # architectures & + # transforms + +import torchvision.transforms as transforms # composable transforms +``` + +### Distributed Training + +``` +import torch.distributed as dist # distributed communication +from torch.multiprocessing import Process # memory sharing processes +``` + +## Tensors { .cols-1 } + +### Creation + +``` +x = torch.randn(*size) # tensor with independent N(0,1) entries +x = torch.[ones|zeros](*size) # tensor with all 1's [or 0's] +x = torch.tensor(L) # create tensor from [nested] list or ndarray L +y = x.clone() # clone of x +with torch.no_grad(): # code wrap that stops autograd from tracking tensor history +requires_grad=True # arg, when set to True, tracks computation + # history for future derivative calculations +``` + +### Dimensionality + +``` +x.size() # return tuple-like object of dimensions +x = torch.cat(tensor_seq, dim=0) # concatenates tensors along dim +y = x.view(a,b,...) # reshapes x into size (a,b,...) +y = x.view(-1,a) # reshapes x into size (b,a) for some b +y = x.transpose(a,b) # swaps dimensions a and b +y = x.permute(*dims) # permutes dimensions +y = x.unsqueeze(dim) # tensor with added axis +y = x.unsqueeze(dim=2) # (a,b,c) tensor -> (a,b,1,c) tensor +y = x.squeeze() # removes all dimensions of size 1 (a,1,b,1) -> (a,b) +y = x.squeeze(dim=1) # removes specified dimension of size 1 (a,1,b,1) -> (a,b,1) +``` + +### Algebra + +``` +ret = A.mm(B) # matrix multiplication +ret = A.mv(x) # matrix-vector multiplication +x = x.t() # matrix transpose +``` + +### GPU Usage + +``` +torch.cuda.is_available # check for cuda +x = x.cuda() # move x's data from + # CPU to GPU and return new object + +x = x.cpu() # move x's data from GPU to CPU + # and return new object + +if not args.disable_cuda and torch.cuda.is_available(): # device agnostic code + args.device = torch.device('cuda') # and modularity +else: # + args.device = torch.device('cpu') # + +net.to(device) # recursively convert their + # parameters and buffers to + # device specific tensors + +x = x.to(device) # copy your tensors to a device + # (gpu, cpu) +``` + +### Deep Learning + +``` +nn.Linear(m,n) # fully connected layer from + # m to n units + +nn.ConvXd(m,n,s) # X dimensional conv layer from + # m to n channels where X⍷{1,2,3} + # and the kernel size is s + +nn.MaxPoolXd(s) # X dimension pooling layer + # (notation as above) + +nn.BatchNormXd # batch norm layer +nn.RNN/LSTM/GRU # recurrent layers +nn.Dropout(p=0.5, inplace=False) # dropout layer for any dimensional input +nn.Dropout2d(p=0.5, inplace=False) # 2-dimensional channel-wise dropout +nn.Embedding(num_embeddings, embedding_dim) # (tensor-wise) mapping from + # indices to embedding vectors +``` + +### Loss Functions + +``` +nn.X # where X is L1Loss, MSELoss, CrossEntropyLoss + # CTCLoss, NLLLoss, PoissonNLLLoss, + # KLDivLoss, BCELoss, BCEWithLogitsLoss, + # MarginRankingLoss, HingeEmbeddingLoss, + # MultiLabelMarginLoss, SmoothL1Loss, + # SoftMarginLoss, MultiLabelSoftMarginLoss, + # CosineEmbeddingLoss, MultiMarginLoss, + # or TripletMarginLoss +``` + +### Activation Functions + +``` +nn.X # where X is ReLU, ReLU6, ELU, SELU, PReLU, LeakyReLU, + # RReLu, CELU, GELU, Threshold, Hardshrink, HardTanh, + # Sigmoid, LogSigmoid, Softplus, SoftShrink, + # Softsign, Tanh, TanhShrink, Softmin, Softmax, + # Softmax2d, LogSoftmax or AdaptiveSoftmaxWithLoss +``` + +### Optimizers + +``` +opt = optim.x(model.parameters(), ...) # create optimizer +opt.step() # update weights +optim.X # where X is SGD, Adadelta, Adagrad, Adam, + # AdamW, SparseAdam, Adamax, ASGD, + # LBFGS, RMSprop or Rprop +``` + +### Learning rate scheduling + +``` +scheduler = optim.X(optimizer,...) # create lr scheduler +scheduler.step() # update lr after optimizer updates weights +optim.lr_scheduler.X # where X is LambdaLR, MultiplicativeLR, + # StepLR, MultiStepLR, ExponentialLR, + # CosineAnnealingLR, ReduceLROnPlateau, CyclicLR, + # OneCycleLR, CosineAnnealingWarmRestarts, +``` + +## Data Utilities { .cols-1 } + +### Datasets + +``` +Dataset # abstract class representing dataset +TensorDataset # labelled dataset in the form of tensors +Concat Dataset # concatenation of Datasets +``` + +### Dataloaders and DataSamplers + +``` +DataLoader(dataset, batch_size=1, ...) # loads data batches agnostic + # of structure of individual data points + +sampler.Sampler(dataset,...) # abstract class dealing with + # ways to sample from dataset + +sampler.XSampler where ... # Sequential, Random, SubsetRandom, + # WeightedRandom, Batch, Distributed +``` \ No newline at end of file diff --git a/source/assets/icon/pytorch.svg b/source/assets/icon/pytorch.svg new file mode 100644 index 0000000..a1940f0 --- /dev/null +++ b/source/assets/icon/pytorch.svg @@ -0,0 +1,2 @@ + +PyTorch icon \ No newline at end of file