Skip to content

Instantly share code, notes, and snippets.

View thecharlieblake's full-sized avatar

Charlie Blake thecharlieblake

View GitHub Profile
from torch import manual_seed, nn, optim, randn
manual_seed(1234)
### Uncomment one of these lines -> in both cases y2 comes out the same!
lr = 1; mult = 1e-3; init_std = 1 / mult;
# lr = 1e-3; mult = 1; init_std = 1
l = nn.Linear(1024, 2048, bias=False)
nn.init.normal_(l.weight, std=init_std)
model = lambda x: l(x) * mult
@thecharlieblake
thecharlieblake / np2torch.py
Last active October 13, 2023 11:39
Given a numpy function, prints equivalent PyTorch code (as canonical ATen ops) and returns it as a new function.
from typing import Callable, List
import numpy as np
import torch
from torch._dynamo.backends.common import aot_autograd
from torch.fx.graph_module import GraphModule
# NOTE: requires torch >= 2.1.0
def np2torch(fn: Callable) -> Callable:
@thecharlieblake
thecharlieblake / int_format.py
Created October 13, 2022 15:45
A representation of the two's complement format used for INT8.
"""A representation of the two's complement format used for INT8."""
from dataclasses import dataclass
from functools import total_ordering
from typing import Any
@dataclass
class TwosComplementFormat:
"""Can be used to express any two's complement signed integer."""
@thecharlieblake
thecharlieblake / float_format.py
Created October 13, 2022 15:43
A representation of the IEEE754 binary format, as well as variants for FP8.
"""A representation of the IEEE754 binary format, as well as variants for FP8."""
from dataclasses import dataclass
from functools import total_ordering
from typing import Any, ClassVar
@dataclass
class IEEE754BinaryFormat:
"""Can be used to express any format defined in the IEEE754 standard.
import numpy as np
class Matmul:
def __init__(self, batch_sz, in_dim, out_dim):
self.batch_sz, self.in_dim, self.out_dim = batch_sz, in_dim, out_dim
glorot = np.sqrt(2 / (in_dim * out_dim))
self._init_w(scale=glorot)
def _init_w(self, scale):
@thecharlieblake
thecharlieblake / rachel.dart
Last active December 18, 2020 11:12
For Rachel
class ProductGrid extends StatelessWidget {
ProductGrid(this.userDocs);
List<DocumentSnapshot> userDocs;
IndividualProduct createProductFromSnapshot(DocumentSnapshot document) {
return IndividualProduct(
document["product_name"],
document["image"][0],
document["discounted_price"].toString()
/* Copyright 2014 Jan Wolter */
#include "stack.h"
#include "tableau.h"
#include "found.h"
#include "bouquet.h"
#include "solve.h"
#include "game.h"
char *gamename= "Canfield";
char *gameopt= "OF";

A checklist of things to do for each feature

  1. Select the next logical feature
  2. Create a task for it
  3. Create some initial subtasks for it
  4. Create a branch
  5. Create the module/interface/package and insert it where it needs to go
  6. Document it
  7. Write integration tests
  8. Ensure tests red
mv .bashrc .bashrc.bak
git clone --bare https://github.com/thecharlesblake/cfg.git $HOME/.cfg
function config {
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
config checkout
config config --local status.showUntrackedFiles no
config submodule update --init --recursive