Skip to content

Instantly share code, notes, and snippets.

@hiropppe
hiropppe / async_distributed_mnist_training.py
Last active February 16, 2017 04:30
Distributed Tensorflow 0.12.0 example of using data parallelism and share model parameters. This is roughly a copy of ischlag (https://github.com/ischlag/distributed-tensorflow-example)
'''
Asynchronous Distributed Tensorflow 0.12.0 example of using data parallelism and share model parameters.
Trains a simple sigmoid neural network on mnist for 20 epochs on three machines using one parameter server.
Change the hardcoded host urls below with your own hosts.
Run like this:
pc-01$ python asynchronous_distributed_mnist_training.py --job_name="ps" --task_index=0
pc-02$ python asynchronous_distributed_mnist_training.py --job_name="worker" --task_index=0
pc-03$ python asynchronous_distributed_mnist_training.py --job_name="worker" --task_index=1
@hiropppe
hiropppe / synchronous_distributed_mnist_training.py
Created February 16, 2017 04:31
Distributed Tensorflow 0.12.0 example of using data parallelism and share model parameters. This is roughly a copy of ischlag (https://github.com/ischlag/distributed-tensorflow-example)
'''
Synchronous Distributed Tensorflow 0.12.0 example of using data parallelism and share model parameters.
Trains a simple sigmoid neural network on mnist for 20 epochs on three machines using one parameter server.
Change the hardcoded host urls below with your own hosts.
Run like this:
pc-01$ python synchronous_distributed_mnist_training.py --job_name="ps" --task_index=0
pc-02$ python synchronous_distributed_mnist_training.py --job_name="worker" --task_index=0
pc-03$ python synchronous_distributed_mnist_training.py --job_name="worker" --task_index=1
from cython.parallel import prange
from libc.stdio cimport printf
from libc.stdlib cimport abort, malloc, free
cimport openmp
def get_int_flag():
cdef int flag = 0
@hiropppe
hiropppe / cython_dot_sample_for_nogil.pyx
Last active June 5, 2017 07:31
Simple cython dot product sample for nogil
# cython: boundscheck = False
# cython: wraparound = False
# cython: cdivision = True
import numpy as np
cimport numpy as np
from scipy.linalg cimport cython_blas
# -*- coding:utf-8 -*-
import codecs
import json
import os
import sys
if __name__ == '__main__':
def walk_json(path):
@hiropppe
hiropppe / nvidia-docker2_g3.4xlarge_setup.txt
Last active June 11, 2018 04:58
nvidia-docker2 setup instruction for for Ubuntu 16.04 LTS (Xenial Xerus) on EC2 g3.4xlarge.
[2018.6.11]
3 sudo apt update
4 sudo apt upgrade
6 sudo apt install build-essential
11 wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.2.88-1_amd64.deb
12 sudo dpkg -i cuda-repo-ubuntu1604_9.2.88-1_amd64.deb
13 sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
14 sudo apt-get update
15 sudo apt-get install cuda
16 nvidia-smi
@hiropppe
hiropppe / DBPediaDockerfile
Last active January 19, 2018 08:29
DBPediaDockerfile
FROM ubuntu:16.04
RUN mkdir /root/_INSTALL
WORKDIR /root/_INSTALL
RUN sed -i.bak -e "s%http://archive.ubuntu.com/ubuntu/%http://ftp.jaist.ac.jp/pub/Linux/ubuntu/%g" /etc/apt/sources.list
ENV TZ Asia/Tokyo
RUN apt-get update \
@hiropppe
hiropppe / print_twogtp_winratio.py
Last active January 26, 2018 13:22
Simple python script which prints player winning ratio from gogui-twogtp result sgf files.
from __future__ import division
import re
import sys
from collections import defaultdict
is_alternate_game = False
if len(sys.argv) > 1:
is_alternate_game = sys.argv[1] in ('--alternate', '-a')
@hiropppe
hiropppe / pandas_SQL_analytic_and_aggregate_functions_like_operation_sample.py
Last active March 19, 2021 13:07
Pandas で count( * ) over ( partition by ... 的な結果がしたかった
In [1]: import pandas as pd
...:
...: data = {'m': ['m1','m2','m2','m3','m3','m3','m4','m4','m4','m4'],
...: 'e': ['e1','e2','e3','e4','e5','e6','e7','e1','e2','e8'],
...: 'p': [0.9, 0.2, 0.8, 0.7, 0.1, 0.2, 0.3, 0.1, 0.2, 0.4]}
...: df = pd.DataFrame(data)
...: df
...:
Out[1]:
e m p
@hiropppe
hiropppe / pandas_apply_udf_sample.py
Last active February 7, 2018 21:53
Pandasで各行に任意の関数を適用するサンプル。遅いらしい:-)
In [1]: import pandas as pd
In [2]: data = {'a': [0,1,2], 'b': [3,4,5]}
...: df = pd.DataFrame(data)
...: df
...:
Out[2]:
a b
0 0 3
1 1 4