Skip to content

Instantly share code, notes, and snippets.

View wesm's full-sized avatar
💭
➡️ ➡️ ➡️

Wes McKinney wesm

💭
➡️ ➡️ ➡️
View GitHub Profile

PyTorch IR

This document presents the IR as of October 17th 2018. Future changes like mutability might render parts of this document outdated.

PyTorch uses an SSA-based IR, which is built of multiple entities:

  • Graph is generally the outermost container for the program representation. At the moment all programs are mostly pure (modulo special operators like prim::Print or prim::PythonOp), but this will change in the future.
  • Then, there are Blocks, which you can treat as functions. They have a list of inputs and outputs, and a (topologically ordered) list of Nodes. Every Graph has a top-level Block which is (using C lingo) like a main function.
  • Nodes, in turn, represent calls to functions (with possibly multiple arguments and returns).
  • Finally, every single intermediate value that appears in the program is represented using a Value - the root Blocks have a list of input values, and every Node takes them as inputs, and returns some more as outputs. Every Value has a Type a
@cassiozen
cassiozen / pixelbook-dev-setup.md
Last active October 22, 2023 12:06 — forked from denolfe/pixelbook-linux-setup.md
Notes on setting up Pixelbook for development

Pixelbook Setup

Change your channel

Some of the features mentioned in this document only work on the beta or Dev channel. To change your channel:

  1. chrome://help in a browser window
  2. Click Detailed Build Information
  3. Change Channel
  4. Select Beta (Or Dev, if you're feeling adventurous)
@daien
daien / multidim_digitize.py
Created December 22, 2011 10:34
Build a regular grid and assigns each data point to a cell
import numpy as np
def regular_multidim_digitize(data, n_bins=3, lbes=None, rbes=None):
""" Build a regular grid and assigns each data point to a cell
Parameters
----------
data: (n_points, n_dims) array,
the data that we which to digitize
@tebeka
tebeka / sumtuples.py
Created November 1, 2011 17:58
Sum tuples of data using sqlite3
#!/usr/bin/env python
import sqlite3
def sumtuples(data, key_index):
cur = sqlite3.connect(':memory:').cursor()
cols = ['i{0}'.format(i) for i, _ in enumerate(data[0])]
schema = 'CREATE TABLE items ({0})'.format(','.join(cols))
cur.execute(schema)
@evansd
evansd / heapqutils.py
Created May 17, 2011 17:18
Some useful iterator functions
# For more explanation and usage examples, see:
# http://www.drhevans.com/blog/posts/331-comparing-large-data-sets-in-python/
from itertools import imap, izip, count, repeat, tee
import heapq
def full_outer_join(*iterables, **kwargs):
"""
Perform a full outer join on a sequence of sorted iterables, where the
key function supplies the join condition.
@CerebralMastication
CerebralMastication / pivot.R
Created April 1, 2011 14:24
Joshua Ulrich's pivot() function for R
## Joshua Ulrich's pivot function
## This code is alpha and is in development.
## please test all results to ensure accuracy
pivot <- function(x, rows, cols, FUN=NULL) {
clean <- function(xx, dd) {
cd <- merge(dd,xx,by=0,all=TRUE)
rownames(cd) <- cd$Row.names
cd$Row.names <- NULL
return(cd)
@huyng
huyng / matplotlibrc
Created February 8, 2011 15:50
my default matplotlib settings
### MATPLOTLIBRC FORMAT
# This is a sample matplotlib configuration file - you can find a copy
# of it on your system in
# site-packages/matplotlib/mpl-data/matplotlibrc. If you edit it
# there, please note that it will be overridden in your next install.
# If you want to keep a permanent local copy that will not be
# over-written, place it in HOME/.matplotlib/matplotlibrc (unix/linux
# like systems) and C:\Documents and Settings\yourname\.matplotlib
# (win32 systems).