Skip to content

Instantly share code, notes, and snippets.

View philtomson's full-sized avatar

Phil Tomson philtomson

View GitHub Profile
@philtomson
philtomson / gist:342e5f8330a46eb2793ffa50d90ca575
Created February 2, 2024 02:38
PYTORCH TIP: mixed precision training
"""
Use torch.cuda.amp in PyTorch for mixed precision training.
This method mixes 32-bit and 16-bit data to reduce memory use and speed up model training,
without much loss in accuracy.
It takes advantage of the quick computing of 16-bit data and controls precision by handling specific operations in 32-bit.
This approach offers a balance between speed and accuracy in training models.
"""
import torch
from torch.cuda.amp import autocast, GradScaler
@philtomson
philtomson / sizes
Created January 9, 2019 01:35
matrix sizes
#RNN data sizes:
# x.size() = [64x1000]
f[0] = self.get_f(dag[-1][0].name) # activation func
c[0] = F.sigmoid(self.w_xc(x) + F.linear(h_prev, self.w_hc, None))
h[0] = (c[0]*f[0](self.w_xh(x) + F.linear(h_prev, self.w_hh, None)) +
(1 - c[0])*h_prev)
#h_prev.size() = [64x1000]
#self.w_hc.size() = [1000,1000]
@philtomson
philtomson / emd.jl
Created December 18, 2014 20:57
Histogram Earth Mover Distance in Julia
function emd!(A,B)
@assert(size(A) == size(B))
cost = 0
last_bin = length(A)
for bin = 1:last_bin
delta = A[bin]-B[bin]
if(delta < 0) #more in B than in A
num_to_move = abs(delta)
next_bin = bin+1
#search to the right for place to move 'package'
@philtomson
philtomson / FixedPoint.jl
Last active August 29, 2015 14:09
start of a fixed point package
# 32-bit fixed point; parameter `f` is the number of fraction bits
function create_mask(wp,fp)
(2^wp-1)<<fp + (2^fp-1)
end
abstract FixedPoint <: Real
abstract Fixed <: FixedPoint
#abstract Ufixed <: FixedPoint # unsigned variant
immutable FixedPt{wp,fp} <: Fixed
@philtomson
philtomson / gist:d11fbe0d02a9d3f841c5
Created August 18, 2014 19:14
cubieboard2 bootup
src_smO0 id ie =104
Readytodisabe icache.
Jump to secend Boot.
0.131]
U-Bot 201109-rc1-00003-ge89b14-dity (Ja 0 2014 - 12:5733) llwinner Technology
[ 0.140version:1.10
[ 0.44]pmus ready
[ 0o
@philtomson
philtomson / gist:dbd20f2465edbfd9524a
Created August 18, 2014 18:58
cubieboard2 bootup
c2_v
[ 0.271]after set, dcdc2 mcdc3_vol =l 3_vol = 2800
ldo4_vol = 2800
power_start = 0
sto mno key fet start
draa_set end
[ dnn'titialize ther n_key:boot_init_gpio)
DRV_DISP_In opened
[ 0.521p.output_type=4
[ 0.525womode = .2]NAND: NANt
set tabstop=2
set smarttab
set shiftwidth=2
set autoindent
set expandtab
set backspace=start,indent
set guifont=Inconsolata\ 14
set hlsearch
syntax on
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") |
@philtomson
philtomson / test_async.ml
Created July 9, 2014 21:44
A simple producer-consumer concurrency test using Core.Async
(* compile with:
corebuild -pkg async,unix test_async.native
*)
open Sys
open Async.Std
open Core
let (r,w) = Pipe.create ()
(* producer *)
type 'a tree = Empty | Leaf of 'a | Node of 'a tree * 'a * 'a tree ;;
let rec tree_map f tree =
let rec aux t = match t with
| Empty -> Empty
| Leaf value -> Leaf (f value)
| Node (l,value,r) -> Node ( aux l , f value, aux r) in
aux tree
let rec preorder_print_tree tree =
@philtomson
philtomson / .gvimrc
Created April 12, 2014 19:57
current gvimrc
"set guifont= Droid\ Sans\ Mono\ Slashed
"set guifont=Inconsolata:m12
set guifont=Inconsolata\ 12
"set guifont=Droid\ Sans\ Mono\ Slashed:h16
colorscheme desert
execute pathogen#infect()
let s:ocamlmerlin=substitute(system('opam config var share'),'\n$','','''') . "/ocamlmerlin"
execute "set rtp+=".s:ocamlmerlin."/vim"
execute "set rtp+=".s:ocamlmerlin."/vimbufsync"