Skip to content

Instantly share code, notes, and snippets.

View hvy's full-sized avatar
🏃‍♂️
Focusing

Hiroyuki Vincent Yamazaki hvy

🏃‍♂️
Focusing
View GitHub Profile
@hvy
hvy / gist:174b6448a2de4b2568fd8501e4aa6012
Last active January 22, 2021 02:50
Chainer implementation of pixel shuffle used in sub-pixel convolutions
import numpy as np
from chainer import Variable
from chainer import functions as F
# Pixel shuffle used in sub-pixel convolutions, in Chainer
# https://arxiv.org/pdf/1609.05158v2.pdf
#
# Example:
# Scaling factor: 3
# In shape: (1, 9, 4, 4)
@hvy
hvy / gist:b1f6bb0c4139d5e55a724b7e33d86bc0
Created April 17, 2017 07:33
Chainer Convolution2D and Deconvolution2D comparison
from chainer import Variable
from chainer import links as L
import numpy as np
# Compare single-channel Convolution2D with Deconvolution2D
h = 128
w = 128
x = np.arange(h * w, dtype=np.float32)
x = x.reshape(1, 1, h, w)
import argparse
import numpy
import chainer
import chainer.functions as F
import chainer.links as L
from chainer import training
from chainer.training import extensions
@hvy
hvy / profile.py
Created August 16, 2017 05:27
cProfile from the cli with environ variables as output filenames similar to nvprof
# https://github.com/python/cpython/blob/master/Lib/profile.py
def _show(self, prof, filename, sort):
if filename is not None:
# NOTE(hvy): Replace environment variables similar to how
# nvprof does by e.g. replacing out_%q{MV2_COMM_WORLD_RANK} with
# out_1, out_2, etc. depending on the value of the variable
# MV2_COMM_WORLD_RANK
import re
if re.search(r'\%q{(.*?)\}', filename) is not None:
filename = re.sub(r'\%q{(.*?)\}',
This file has been truncated, but you can view the full file.
Started by upstream project "chainer/chainer_pr" build number 333
originally caused by:
GitHub pull request #6441 of commit 87e4eb6f662973b13d7b565c55a6ad71982fb283, no merge conflicts.
Building remotely on gpcl-gpu205 (mn1-p100 sakura11) in workspace /home/jenkins-external-slave/workspace/chainer/chainer_pr/TEST/CHAINERX_misc/label/mn1-p100
using credential 40bb97f1-7bf9-4f59-b66e-8d81d634b1a9
Wiping out workspace first.
Cloning the remote Git repository
Cloning repository [email protected]:chainer/chainer-test.git
> git init /home/jenkins-external-slave/workspace/chainer/chainer_pr/TEST/CHAINERX_misc/label/mn1-p100 # timeout=10
Fetching upstream changes from [email protected]:chainer/chainer-test.git
@hvy
hvy / quadratic_joblib_arbitrary_arguments_simple.py
Last active December 7, 2020 04:45
Optuna example that optimizes a simple quadratic function in parallel using joblib with arbitrary arguments to the objective function.
"""
Optuna example that optimizes a simple quadratic function in parallel using `joblib` allowing
arbitrary arguments to the objective function.
Run the example as follows.
$ python quadratic_joblib_simple.py
If you need to rerun the example and thus delete previous studies, you can use the Optuna CLI.
@hvy
hvy / optuna-coding-style-public-private
Last active November 15, 2019 04:46
Optuna public/private visibility coding style
## Add `_` prefix to the names of private interfaces.
Interfaces in `optuna`, i.e. submodules, classes and attributes are either public, private for internal use in `optuna` or private for internal use within a parcitular class. Private interfaces are not part of the public API and are not expected to be directly used by the library user. They are only meant for internal use in `optuna`. This reserves them for future changes and allows modifications without breaking compatibility. It is therefore important to clearly communciate whether an interfaces is public or private and `optuna` distinigushes between them as follows.
Reference: https://docs.python.org/3/tutorial/classes.html#private-variables.
### Good
```python
def public_function(): # Used by users.
@hvy
hvy / logging_tqdm_multiprocessing.py
Created January 30, 2020 01:33
Experimental `joblib.register_parallel_backend` to render progress bar.
import logging
import threading
import time
import joblib
import tqdm
class TqdmLoggingHandler(logging.StreamHandler):
def emit(self, record):
from collections import OrderedDict
import time
from matplotlib import pyplot as plt
import optuna
from optuna import samplers
from optuna.storages import RDBStorage
from optuna.storages import RedisStorage
@hvy
hvy / fanova_comparison.py
Created April 7, 2020 12:40
Plots importances evaluated by fANOVA (AutoML.org) and Fanova (sklearn based implementation).
"""
Plots importances evaluated by fANOVA (AutoML.org) and Fanova (sklearn based implementation).
1. Loads data from csv containing parameter configuration-objective value pairs.
2. Loads search space definitions from csv.
3. Evaluates all single and pairwise importances between parameters.
4. Repeats evaluation N times (with different random seeds).
5. Plots the average over N evaluations.
"""
import argparse