Skip to content

Instantly share code, notes, and snippets.

View apivovarov's full-sized avatar

Alexander Pivovarov apivovarov

  • Amazon Web Services
  • Santa Clara, CA
  • 12:35 (UTC -07:00)
  • LinkedIn in/pivovaal
View GitHub Profile
@apivovarov
apivovarov / build-clang.sh
Last active September 18, 2024 01:39
build clang
cmake -S llvm -B build \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld" \
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
-DLLVM_TARGETS_TO_BUILD=host \
-DLLVM_INCLUDE_TESTS=OFF
cmake --build build -j48
sudo cmake --build build -j48 -t install
@apivovarov
apivovarov / hlo_convert_torch_xla.py
Created August 23, 2024 21:47
[torch_xla] convert hlo.pb to text hlo
import torch_xla.core.xla_builder as xb
fname = "model.hlo.pb"
with open(fname, mode="rb") as f:
comp = xb.computation_from_module_proto("foo", f.read())
print(xb.get_computation_hlo(comp))
@apivovarov
apivovarov / hlo_convert_jax.py
Created August 23, 2024 21:46
[JAX] convert hlo.pb to text hlo
from jax.lib.xla_bridge import xla_client
fname = "model.hlo.pb"
with open(fname, mode="rb") as f:
comp = xla_client.XlaComputation(f.read())
print(comp.as_hlo_text())
@apivovarov
apivovarov / start-docker.sh
Created June 12, 2024 23:21
start-docker as user
docker run -ti --name u2204 -v ~/workspace:/home/joshcao/workspace ubuntu:22.04
U=pivovaa
apt update
apt install -y adduser sudo vim wget curl \
libssl-dev \
python3 python3-pip
adduser $U
@apivovarov
apivovarov / hlo-opt-help.txt
Created June 12, 2024 16:44
./bazel-bin/xla/tools/hlo-opt --help
This tool lets you run a given HloModule from a file (or stdin) and convert it
to expanded HLO, fully optimized HLO, or a binary depending on options.
HLO passes are always run, unless the HLO module is already scheduled (has
is_scheduled=True).
You can also pass in debug option flags for the HloModule.
Usage:
@apivovarov
apivovarov / grad.py
Last active November 15, 2023 23:39
a = 5
b = 6
y = a/b
h = 0.00001
def dy_da_f():
a2 = a + h
y2 = a2 / b
dy_da = (y2 - y) / h
import jax
from jax import Array
import jax.numpy as jnp
def init_params(key: Array, shape) -> Array:
return jax.random.normal(key, shape).astype(jax.dtypes.bfloat16)
def softmax(x):
mx = x.max(axis=-1, keepdims=True)
mx = jax.lax.stop_gradient(mx)
HloModule xla_computation_ff, entry_computation_layout={(f32[1,224,224,3]{3,2,1,0})->(f32[1,224,224,3]{3,2,1,0})}
ENTRY main.20 {
Arg_0.1 = f32[1,224,224,3]{3,2,1,0} parameter(0)
multiply.10 = f32[1,224,224,3]{3,2,1,0} multiply(Arg_0.1, Arg_0.1)
multiply.11 = f32[1,224,224,3]{3,2,1,0} multiply(Arg_0.1, multiply.10)
constant.8 = f32[] constant(0.044715)
broadcast.9 = f32[1,224,224,3]{3,2,1,0} broadcast(constant.8), dimensions={}
multiply.12 = f32[1,224,224,3]{3,2,1,0} multiply(multiply.11, broadcast.9)
add.13 = f32[1,224,224,3]{3,2,1,0} add(Arg_0.1, multiply.12)
HloModule xla_computation_ff, entry_computation_layout={(f32[4,1000]{1,0})->(f32[4,1000]{1,0})}
region_0.4 {
Arg_0.5 = f32[] parameter(0)
Arg_1.6 = f32[] parameter(1)
ROOT maximum.7 = f32[] maximum(Arg_0.5, Arg_1.6)
}
region_1.15 {
Arg_0.16 = f32[] parameter(0)
@apivovarov
apivovarov / nrvo.cc
Created September 19, 2023 23:38
NRVO Test
#include <iostream>
#include <vector>
std::vector<int> testNRVO(int value, size_t size, const std::vector<int> **localVec)
{
std::vector<int> vec(size, value);
*localVec = &vec;
/* Do something here.. */