Skip to content

Instantly share code, notes, and snippets.

@JonathanRaiman
JonathanRaiman / human.cpp
Last active November 27, 2018 02:25
Code auto generated by Dali
auto a = op::uniform(-20.0, 20.0, {2, 5}).astype(dtype);
a.eval();
auto exped = op::exp(a - op::max(a, {-1}, true));
auto fused_softmax = exped / op::sum(exped, {-1}, true);
@JonathanRaiman
JonathanRaiman / access_pattern.py
Last active April 29, 2018 07:27
Access Pattern inference
"""
Access Pattern Search
---------------------
Code for simulating the effect of searching for the right access pattern in
a CUDA Kernel computation directed acyclic graph.
The key idea is to have every node in the computation graph return an object
representing "for loops" that can be optionally parallelized using blocks
or threads (followed by syncs).
@JonathanRaiman
JonathanRaiman / clear_subl.sh
Created March 30, 2018 21:19
Clears out window cache of sublime which can cause issues on boot up (MacOSX)
function clear_subl {
python3 -c "path = '~/Library/Application Support/Sublime Text 3/Local/Auto Save Session.sublime_session'; import os, json; data = json.load(open(os.path.expanduser(path), 'rt')); data['windows'] = []; json.dump(data, open(os.path.expanduser(path), 'wt'))"
}
@JonathanRaiman
JonathanRaiman / graph_optimization.py
Created July 29, 2018 22:00
Memoized Graph Optimization
from contextlib import contextmanager
import time
CURRENT_SCOPE = []
@contextmanager
def printing_scope(message):
CURRENT_SCOPE.append(message)
yield
last = CURRENT_SCOPE.pop()
@JonathanRaiman
JonathanRaiman / google_tsp_solver.py
Created February 6, 2019 19:46
approximate tsp solver
from ortools.constraint_solver import pywrapcp
import numpy as np
def _create_distance_callback(dist_matrix):
# Create a callback to calculate distances between cities.
def distance_callback(from_node, to_node):
return int(dist_matrix[from_node][to_node])
return distance_callback
@JonathanRaiman
JonathanRaiman / save_submission.py
Last active October 6, 2021 02:53
Code to submit predictions to cardinality estimation leaderboard @ ML for Systems NeurIPS 2021 workshop
import numpy as np
def save_submission(predictions, filename):
"Take model output & save for cardinality estimation benchmark upload."""
np.save(filename, np.array([value for item in predictions for key, value in sorted(item.items())]))
# preds = rf.test(testqs) # run your prediction code on the test data
save_submission(preds, "mysubmission.npy")
# Then Upload "mysubmission.npy" to the leaderboard https://mlforsystems.wl.r.appspot.com :)