This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sample_gumbel(shape, eps=1e-20): | |
"""Sample from Gumbel(0, 1)""" | |
U = tf.random_uniform(shape,minval=0,maxval=1) | |
return -tf.log(-tf.log(U + eps) + eps) | |
def gumbel_softmax_sample(logits, temperature): | |
""" Draw a sample from the Gumbel-Softmax distribution""" | |
y = logits + sample_gumbel(tf.shape(logits)) | |
return tf.nn.softmax( y / temperature) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
from torch.autograd import Variable | |
def sample_gumbel(shape, eps=1e-20): | |
U = torch.rand(shape).cuda() | |
return -Variable(torch.log(-torch.log(U + eps) + eps)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Usage: | |
python convert.py xxx.rst xxx.py | |
To convert markdown to sphinx_gallery `.py`, use pandoc to generate a `.rst` text in advance: | |
pandoc xxx.md --output xxx.rst | |
python convert.py xxx.rst xxx.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This part for jupyter notebook setting (if you wants to save, don't use this) | |
# %matplotlib inline | |
# %config InlineBackend.figure_format = 'svg' | |
# import numpy as np | |
# import matplotlib.pyplot as plt | |
# plt.rcParams["animation.html"] = "jshtml" | |
import networkx as nx | |
from networkx.algorithms import bipartite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This code was modified from the GCN implementation in DGL examples. | |
Simplifying Graph Convolutional Networks | |
Paper: https://arxiv.org/abs/1902.07153 | |
Code: https://github.com/Tiiiger/SGC | |
SGC implementation in DGL. | |
""" | |
import argparse, time, math |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Training graphsage w/ fp16. | |
Usage: | |
python train_full.py --gpu 0 --fp16 --dataset | |
Note that GradScaler is not acitvated because the model successfully converges | |
without gradient scaling. | |
DGL's Message Passing APIs are not compatible with fp16 yet, hence we disabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dgl | |
import dgl.ops as ops | |
import numpy as np | |
import torch as th | |
import torch.nn as nn | |
class FFN(nn.Module): | |
def __init__(self, d_feat, d_ffn, dropout=0.1): | |
super().__init__() | |
self.linear_0 = nn.Linear(d_feat, d_ffn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
char str[] = "#include <stdio.h>%cchar str[] = %c%s%c;%cint main() {%c printf(str, 10, 34, str, 34, 10, 10, 10);%c}"; | |
int main() { | |
printf(str, 10, 34, str, 34, 10, 10, 10); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prog = "prog = {:c}{}{:c}{:c}print(prog.format(34, prog, 34, 10))" | |
print(prog.format(34, prog, 34, 10)) |
OlderNewer