Skip to content

Instantly share code, notes, and snippets.

# Lifted verbatim from https://pytorch.org/tutorials/beginner/knowledge_distillation_tutorial.html
# Only for illustrating the distillation training loop as a code fragment.
for epoch in range(epochs):
running_loss = 0.0
for inputs, labels in train_loader:
inputs, labels = inputs.to(device), labels.to(device)
optimizer.zero_grad()
@aurotripathy
aurotripathy / softmax-temperature.ipynb
Created February 4, 2024 00:07
softmax temp illustration
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""
Time the all_reduce_sum operation with model parameters size of the VGG-16 model (~138M floats)
1. Paramters are loaded into each of the N=4 GPUs
2. nccl.all_reduce is invoked on the paramters
TO get a breakdown of the VGG model size, see...
https://stackoverflow.com/questions/28232235/how-to-calculate-the-number-of-parameters-of-convolutional-neural-networks
"""
from __future__ import print_function
import torch
class MyLinearLayer(nn.Module):
""" Custom Linear layer but mimics a standard linear layer """
def __init__(self, size_in, size_out):
super().__init__()
self.size_in, self.size_out = size_in, size_out
weights = torch.Tensor(size_out, size_in)
self.weights = nn.Parameter(weights) # nn.Parameter is a Tensor that's a module parameter.
bias = torch.Tensor(size_out)
self.bias = nn.Parameter(bias)
# Dataset utils and dataloaders
import glob
import logging
import math
import os
import random
import shutil
import time
from itertools import repeat
#!/usr/bin/env python3
import logging
import os
from furiosa import runtime
from furiosa.runtime import session
import numpy as np
LOGLEVEL = os.environ.get('FURIOSA_LOG_LEVEL', 'INFO').upper()
logging.basicConfig(level=LOGLEVEL)
#!/usr/bin/env python3
"""
Calibration data/images is from the data folder
from https://github.com/derronqi/yolov7-face
"""
import sys
import onnx
import torch
"""
The model is from https://github.com/derronqi/yolov7-face
Here, we download yolov7s-face.pt and convert it.
Output is model.onnx
"""
import torch
from models.experimental import attempt_load
from pudb import set_trace
from utils.torch_utils import select_device
batch_size = 1
@aurotripathy
aurotripathy / nexoptics_tfl_model.py
Created April 4, 2023 08:41
missing depth2space op
import logging
import os
from furiosa import runtime
from furiosa.runtime import session
import numpy as np
LOGLEVEL = os.environ.get('FURIOSA_LOG_LEVEL', 'INFO').upper()
logging.basicConfig(level=LOGLEVEL)
@aurotripathy
aurotripathy / compile_run.py
Created April 3, 2023 15:50
example of a model that does not fit.
#!/usr/bin/env python3
import logging
import os
from furiosa import runtime
from furiosa.runtime import session
import numpy as np
LOGLEVEL = os.environ.get('FURIOSA_LOG_LEVEL', 'INFO').upper()
logging.basicConfig(level=LOGLEVEL)