Skip to content

Instantly share code, notes, and snippets.

from __future__ import print_function
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import apex
class Net(nn.Module):
--- /tmp/after 2018-05-14 15:18:24.824151538 -0700
+++ /tmp/before 2018-05-14 15:18:38.465234656 -0700
@@ -530,18 +530,8 @@
}
}
node {
- input: "48"
- output: "51"
- op_type: "Squeeze"
- attribute {

Consider a full training pipeline. Roughly speaking, we can break it up into "preprocessing" and "model", using the distinction that everything that does not (transitively) depend on learnable weights is a preprocessing step.

The question is: are preprocessing steps in scope for ONNX?

The main points in favor are

  • Having automatic translation between frameworks of the entire
>>> from onnx import ValueInfoProto
>>> x = ValueInfoProto()
>>> y = ValueInfoProto()
>>> x == y
True
>>> x.type.tensor_type.shape.dim.extend([])
>>> x == y
False
>>> x
type {
@anderspapitto
anderspapitto / gist:01af001e5a6af3e424ee172a77a7f7e0
Created March 8, 2018 19:17
shape inference example, using IR representation
.ShapeInferenceFunction([](const Node* n, NodeOutTypes& out_types, NodeOutSizes& out_dims) {
auto inp = n->inputs()[0];
auto out = n->outputs()[0];
out_types.push_back(inp->hasElemType() ? inp->elemType() : ONNX_NAMESPACE::TensorProto_DataType_UNDEFINED);
out_dims.emplace_back();
if (!inp->sizes().empty()) {
for (size_t i = 0; i < inp->sizes().size(); i++) {
size_t idx = n->hasAttribute(kperm)
? n->is(kperm)[i]
: inp->sizes().size() - i - 1
@anderspapitto
anderspapitto / gist:5dd869c13eeaa9732f4bc0d34db6c068
Created March 8, 2018 19:12
shape inference example, operating directly on proto structs
.ShapeInferenceFunction([](GraphProto* g, NodeProto* n) {
std::vector<int64_t> perm;
for (int i = 0; i < n->attribute_size(); i++) {
auto attr = n->attribute(i);
if (attr.has_name() && attr.name() == "perm") {
for (int j = 0; j < attr.ints_size(); j++) {
perm.push_back(attr.ints(j));
}
}
}
running 107 tests
test [debuginfo-gdb] debuginfo-gdb/basic-types-globals.rs ... FAILED
test [debuginfo-gdb] debuginfo-gdb/basic-types-globals-metadata.rs ... ok
test [debuginfo-gdb] debuginfo-gdb/basic-types-metadata.rs ... ok
test [debuginfo-gdb] debuginfo-gdb/associated-types.rs ... ok
test [debuginfo-gdb] debuginfo-gdb/basic-types-mut-globals.rs ... FAILED
test [debuginfo-gdb] debuginfo-gdb/borrowed-enum.rs ... ignored
test [debuginfo-gdb] debuginfo-gdb/basic-types.rs ... ok
test [debuginfo-gdb] debuginfo-gdb/borrowed-basic.rs ... ok
test [debuginfo-gdb] debuginfo-gdb/borrowed-c-style-enum.rs ... ok
@anderspapitto
anderspapitto / gist:a5d1e6207226634b3137
Created March 7, 2015 17:11
suspend-to-ram bug X logs
[ 3.941]
X.Org X Server 1.16.4
Release Date: 2014-12-20
[ 3.941] X Protocol Version 11, Revision 0
[ 3.941] Build Operating System: Linux 3.12.27 x86_64
[ 3.941] Current Operating System: Linux gurney 3.19.0 #1-NixOS SMP Thu Jan 1 00:00:01 UTC 1970 x86_64
[ 3.941] Kernel command line: initrd=\efi\nixos\sn2qp3ny304badksm1j0pr0q5xv1vwi3-initrd-initrd.efi systemConfig=/nix/store/dwhyf067ay6hfhvkwpn73hs4ngfz6z0s-nixos-15.05pre58357.a869c83 init=/nix/store/dwhyf067ay6hfhvkwpn73hs4ngfz6z0s-nixos-15.05pre58357.a869c83/init loglevel=4
[ 3.941] Build Date: 20 February 2015 12:36:56PM
[ 3.941]
[ 3.941] Current version of pixman: 0.32.6
@anderspapitto
anderspapitto / gist:3841395e3c95b167dcab
Created March 7, 2015 03:40
suspend-to-ram bug logs
-- Logs begin at Sat 2015-02-14 17:45:21 PST, end at Fri 2015-03-06 19:34:41 PST. --
Mar 06 19:13:55 gurney systemd-journal[1230]: Runtime journal is using 8.0M (max allowed 196.7M, trying to leave 295.1M free of 1.9G available → current limit 196.7M).
Mar 06 19:13:55 gurney systemd-journal[1230]: Permanent journal is using 96.0M (max allowed 995.1M, trying to leave 1.4G free of 8.8G available → current limit 995.1M).
Mar 06 19:13:55 gurney systemd-journal[1230]: Time spent on flushing to /var is 650us for 2 entries.
Mar 06 19:13:55 gurney kernel: Initializing cgroup subsys cpuset
Mar 06 19:13:55 gurney kernel: Initializing cgroup subsys cpu
Mar 06 19:13:55 gurney kernel: Initializing cgroup subsys cpuacct
Mar 06 19:13:55 gurney kernel: Linux version 3.19.0 (nixbld@localhost) (gcc version 4.8.4 (GCC) ) #1-NixOS SMP Thu Jan 1 00:00:01 UTC 1970
Mar 06 19:13:55 gurney kernel: Command line: initrd=\efi\nixos\sn2qp3ny304badksm1j0pr0q5xv1vwi3-initrd-initrd.efi systemConfig=/nix/store/0292shf32bpfsxb4144zs7d72bqypnp
@anderspapitto
anderspapitto / gist:04bf411c2c919bc89617
Created March 7, 2015 03:23
suspend-to-ram bug hardware-configuration.nix
# Do not modify this file! It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, ... }:
{
imports =
[ <nixpkgs/nixos/modules/installer/scan/not-detected.nix>
];