Skip to content

Instantly share code, notes, and snippets.

View keras_mnist_cnn.py
from __future__ import print_function
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K
import tensorflow as tf
import horovod.tensorflow as hvd
View test_nccl.c
// Code from http://docs.nvidia.com/deeplearning/sdk/nccl-developer-guide/index.html#onedevprothrd
#define _BSD_SOURCE
#include <stdio.h>
#include "cuda_runtime.h"
#include "nccl.h"
#include "mpi.h"
#include <stdint.h>
#include <stdlib.h>
@alsrgv
alsrgv / tensorflow_mnist_estimator.py
Last active Jul 14, 2020
Horovod with Estimator API
View tensorflow_mnist_estimator.py
# Copyright 2017 Uber Technologies, Inc. All Rights Reserved.
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@alsrgv
alsrgv / receptive_fields_keras.py
Last active Apr 1, 2020
Receptive fields for Keras
View receptive_fields_keras.py
import graphviz
import numpy as np
import keras
def gather_layer_stats(layer_dict, layer, r, s):
lr, ls = None, None
if hasattr(layer, 'kernel_size'):
assert layer.kernel_size[0] == layer.kernel_size[1]
assert layer.strides[0] == layer.strides[1]
@alsrgv
alsrgv / horovod_model_parallelism.py
Created Jan 27, 2018
Model parallelism in Horovod
View horovod_model_parallelism.py
# Copyright 2018 Uber Technologies, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@alsrgv
alsrgv / pbtxt_to_pb.py
Created Mar 15, 2018
Converter of graph.pbtxt to binary graph.pb
View pbtxt_to_pb.py
from __future__ import print_function
import os
import sys
import tensorflow as tf
from google.protobuf import text_format
from tensorflow.python.framework import graph_io
if len(sys.argv) < 2:
print('Usage: %s <filename prefix>' % sys.argv[0])
@alsrgv
alsrgv / pytorch_imagenet_resnet50_1late.py
Created Jul 27, 2018
1-late SGD for PyTorch ImageNet example with Horovod
View pytorch_imagenet_resnet50_1late.py
from __future__ import print_function
import argparse
import torch.backends.cudnn as cudnn
import torch.nn.functional as F
import torch.optim as optim
import torch.utils.data.distributed
from torchvision import datasets, transforms, models
import horovod.torch as hvd
import tensorboardX
@alsrgv
alsrgv / hyperas_keras_example.py
Last active Jul 25, 2020
Hyperas + Horovod Example
View hyperas_keras_example.py
from __future__ import print_function
from hyperopt import Trials, STATUS_OK, tpe
from hyperas import optim
from hyperas.distributions import choice, uniform, conditional
import keras
import tensorflow as tf
import horovod.keras as hvd
import keras.backend as K
import math
@alsrgv
alsrgv / tmds.sv
Last active Sep 12, 2021
TMDS encoder/decoder in SystemVerilog
View tmds.sv
package tmds_pkg;
typedef struct packed {
logic inv_q_m;
logic use_xor;
logic [7:0] q_m;
} tmds_encoded_t;
typedef enum logic [9:0]{
CTRL_00 = 10'b1101010100,
@alsrgv
alsrgv / tmds.cpp
Last active Dec 3, 2018
TMDS in C++ HLS
View tmds.cpp
#include <assert.h>
#include "tmds.h"
#include "utils.h"
template<int X>
ap_uint<log2up(X)> count_ones(ap_uint<X> data) {
ap_uint<X> result = data[0];
for (int i = 1; i < 8; i++) {
#pragma HLS UNROLL