Skip to content

Instantly share code, notes, and snippets.

View refraction-ray's full-sized avatar

Shixin Zhang refraction-ray

View GitHub Profile
# zhangqiaorjc@google.com
# `jax.distributed.initialize` is available in jax-0.2.25.
# $ pip install --upgrade "jax[cuda]" -f https://storage.googleapis.com/jax-releases/jax_releases.html # Note: wheels only available on linux.
# Run this script on 2 GPU nodes, assuming 10.128.0.6 is the master node
# python nvidia_gpu_pjit.py --server_addr="10.128.0.6:1456" --num_hosts=2 --host_idx=0
# python nvidia_gpu_pjit.py --server_addr="10.128.0.6:1456" --num_hosts=2 --host_idx=1
from absl import app
from absl import flags
import torch
import torch.utils.dlpack
import jax
import jax.dlpack
# A generic mechanism for turning a JAX function into a PyTorch function.
def j2t(x_jax):
x_torch = torch.utils.dlpack.from_dlpack(jax.dlpack.to_dlpack(x_jax))
return x_torch
@piyueh
piyueh / tf_keras_tfp_lbfgs.py
Last active September 19, 2024 08:45
Optimize TensorFlow & Keras models with L-BFGS from TensorFlow Probability
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2019 Pi-Yueh Chuang <pychuang@gwu.edu>
#
# Distributed under terms of the MIT license.
"""An example of using tfp.optimizer.lbfgs_minimize to optimize a TensorFlow model.
@piyushrpt
piyushrpt / customfeedstock.md
Last active October 21, 2021 20:17
Setting up custom conda feedstock
@msarahan
msarahan / ext.pyx
Last active July 25, 2019 03:32
validation of MKL 2018.0.3 openmp initialization fixes
cimport numpy as np
import numpy as np
import cython
from cython.parallel import prange
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
def p_arange(int n):
'''
@nadavrot
nadavrot / Matrix.md
Last active August 16, 2024 08:59
Efficient matrix multiplication

High-Performance Matrix Multiplication

This is a short post that explains how to write a high-performance matrix multiplication program on modern processors. In this tutorial I will use a single core of the Skylake-client CPU with AVX2, but the principles in this post also apply to other processors with different instruction sets (such as AVX512).

Intro

Matrix multiplication is a mathematical operation that defines the product of

@angela-d
angela-d / gpg-key-migration.md
Created April 1, 2018 23:57
Move GPG Keys from One Machine to Another

Migrate GPG Keys from One Workstation to Another

Replace [your key] with your key ID

To obtain your key ID

gpg --list-secret-keys --keyid-format LONG

Which returns something like

@wiseodd
wiseodd / natural_grad.py
Created March 13, 2018 19:36
Natural Gradient Descent for Logistic Regression
import numpy as np
from sklearn.utils import shuffle
# Data comes from y = f(x) = [2, 3].x + [5, 7]
X0 = np.random.randn(100, 2) - 1
X1 = np.random.randn(100, 2) + 1
X = np.vstack([X0, X1])
t = np.vstack([np.zeros([100, 1]), np.ones([100, 1])])
@gngdb
gngdb / defun.py
Last active March 27, 2019 06:52
how to use Defun to define custom gradients in Tensorflow
import tensorflow as tf
from tensorflow.python.framework import function
@function.Defun()
def my_op_grad(op, grad): ### instead of my_op_grad(x)
return tf.sigmoid(op)
@function.Defun(grad_func=my_op_grad)
def my_op(a):
return tf.identity(a)
@chsasank
chsasank / ipynb_to_gallery.py
Last active February 21, 2024 14:29
Convert jupyter notebook to sphinx gallery notebook styled examples.