Skip to content

Instantly share code, notes, and snippets.

View goldsborough's full-sized avatar
🔨
Fixing things

Peter Goldsborough goldsborough

🔨
Fixing things
View GitHub Profile
@goldsborough
goldsborough / rnn.py
Created February 24, 2018 09:12
RNN/LSTM/GRU in NumPy
import numpy as np
np.random.seed(42)
def sigmoid(z):
return 1 / (1 + np.exp(-z))
def d_sigmoid(z):
@goldsborough
goldsborough / hex.rs
Created March 9, 2018 08:50
hex parser in rust
macro_rules! hex {
(0) => {48};
(9) => {57};
(A) => {65};
(F) => {70};
(a) => {97};
(z) => {102};
(0..9) => {48...57};
(A..F) => {65...70};
(a..f) => {97...102};
test_RNGState (test_torch.TestTorch) ... ok
test_RNGStateAliasing (test_torch.TestTorch) ... ok
test_Size (test_torch.TestTorch) ... ok
test_abs (test_torch.TestTorch) ... ok
test_accreal_type (test_torch.TestTorch) ... ok
test_acos (test_torch.TestTorch) ... ok
test_add (test_torch.TestTorch) ... ok
test_addbmm (test_torch.TestTorch) ... ok
test_addmm (test_torch.TestTorch) ... ok
test_addmv (test_torch.TestTorch) ... ok
diff --git a/torch/csrc/autograd/autograd.h b/torch/csrc/autograd/autograd.h
index f04b472e..7ff9a39f 100644
--- a/torch/csrc/autograd/autograd.h
+++ b/torch/csrc/autograd/autograd.h
@@ -2,12 +2,14 @@
#define THP_AUTOGRAD_H
PyObject * THPAutograd_initExtension(PyObject *_unused);
-bool THPAutograd_initFunctions(PyObject* module);
+void THPAutograd_initFunctions();
@goldsborough
goldsborough / install-gcc.sh
Last active January 1, 2025 17:14
Instructions for installing GCC >= 4.9 for PyTorch Extensions
# Instructions for installing GCC 4.9 on various platforms.
# The commands show instructions for GCC 4.9, but any higher version will also work!
# Ubuntu (https://askubuntu.com/questions/466651/how-do-i-use-the-latest-gcc-on-ubuntu/581497#581497)
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9
const int kRuns = 1000;
const int kWarmUp = 100000;
void benchmark() {
using clock = std::chrono::high_resolution_clock;
using duration = std::chrono::duration<double, std::micro>;
auto x = make_variable(CPU(kFloat).randn({10, 10}), true);
backward(x.sum());
AUTOGRAD_CONTAINER_CLASS(DefoggerModel) {
// Multi level LSTM model from starcraft_defogger.
public:
struct Parameters {
int map_embsize = 64;
int race_embsize = 8;
int dec_convsize = 3;
int dec_depth = 3;
int dec_embsize = 128;
int hid_dim = 256;
Skipping /home/psag/pytorch/pytorch/torch/csrc/api/include/torch/optimizers.h. Compile command not found.
Skipping /home/psag/pytorch/pytorch/torch/csrc/api/include/torch/serialization.h. Compile command not found.
Skipping /home/psag/pytorch/pytorch/torch/csrc/api/include/torch/torch.h. Compile command not found.
Skipping /home/psag/pytorch/pytorch/torch/csrc/api/include/torch/detail.h. Compile command not found.
Skipping /home/psag/pytorch/pytorch/torch/csrc/api/include/torch/nn/module.h. Compile command not found.
Skipping /home/psag/pytorch/pytorch/torch/csrc/api/include/torch/nn/modules/conv.h. Compile command not found.
Skipping /home/psag/pytorch/pytorch/torch/csrc/api/include/torch/nn/modules/modules.h. Compile command not found.
Skipping /home/psag/pytorch/pytorch/torch/csrc/api/include/torch/nn/modules/functional.h. Compile command not found.
Skipping /home/psag/pytorch/pytorch/torch/csrc/api/include/torch/nn/modules/batchnorm.h. Compile command not found.
Skipping /home/psag/pytorch/pytorch/torch/c
@goldsborough
goldsborough / any.cpp
Created May 10, 2018 17:58
Basic implementation of Any
class Any {
public:
template<typename T>
explicit Any(T&& value) : content_(new Holder<T>(std::forward<T>(value))) {}
Any(const Any& other) : content_(other.content_->clone()) {}
Any(Any&& other) { swap(other); }
insert_at_end_unordered_set_small_string(100000 14.41ms 69.42
insert_at_end_sorted_vector_set_small_string(10 353.95ns 2.83M
insert_at_end_sorted_vector_set_small_string(10 7.74us 129.14K
insert_at_end_sorted_vector_set_small_string(10 791.95us 1.26K
insert_at_end_sorted_vector_set_small_string(10 65.09ms 15.36
insert_at_end_sorted_vector_set_small_string(10 6.90s 144.85m
insert_at_end_unordered_set_large_string(100000 27.17ms 36.81
insert_at_end_sorted_vector_set_large_string(10 1.07us 932.14K
insert_at_end_sorted_vector_set_large_string(10 16.40us 60.99K
insert_at_end_sorted_vector_set_large_string(10 507.14us 1.97K