Skip to content

Instantly share code, notes, and snippets.

View apivovarov's full-sized avatar

Alexander Pivovarov apivovarov

  • Amazon Web Services
  • Santa Clara, CA
  • 09:35 (UTC -08:00)
  • LinkedIn in/pivovaal
View GitHub Profile
@apivovarov
apivovarov / gist:bcec4892e79fd8d335d7007da88d6e19
Created December 15, 2024 01:55
operator<< for std::vector
template<typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> arr) {
os << "[";
for (int i = 0; i < arr.size(); ++i) {
if (i > 0) os << ",";
os << arr[i];
}
os << "]";
return os;
}
@apivovarov
apivovarov / torch-neuronx-al2-setup.sh
Created October 16, 2024 21:49
torch-neuronx Setup on Amazon Linux 2
# Configure Linux for Neuron repository updates
sudo tee /etc/yum.repos.d/neuron.repo > /dev/null <<EOF
[neuron]
name=Neuron YUM Repository
baseurl=https://yum.repos.neuron.amazonaws.com
enabled=1
metadata_expire=0
EOF
sudo rpm --import https://yum.repos.neuron.amazonaws.com/GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB
@apivovarov
apivovarov / get_compatibility_versions.py
Last active October 17, 2024 01:57
StableHLO get_compatibility_versions.py
import subprocess
import time
utc = int(time.time())
shell_script = """
git for-each-ref --sort=taggerdate \
--format '%(refname:short),%(taggerdate:unix),%(taggerdate:short)' refs/tags \
| tail -40 \
| tac
% pylint xla/python
************* Module python.xla_client_test
xla/python/xla_client_test.py:3177:0: C0301: Line too long (99/80) (line-too-long)
xla/python/xla_client_test.py:3180:0: C0301: Line too long (86/80) (line-too-long)
xla/python/xla_client_test.py:3355:0: C0301: Line too long (87/80) (line-too-long)
************* Module python.xla_client
xla/python/xla_client.pyi:74:0: C0301: Line too long (86/80) (line-too-long)
xla/python/xla_client.pyi:81:0: C0301: Line too long (81/80) (line-too-long)
xla/python/xla_client.pyi:107:0: C0301: Line too long (83/80) (line-too-long)
xla/python/xla_client.pyi:115:0: C0301: Line too long (96/80) (line-too-long)
pylint xla/python
************* Module python.xla_client_test
xla/python/xla_client_test.py:3177:0: C0301: Line too long (99/80) (line-too-long)
xla/python/xla_client_test.py:3180:0: C0301: Line too long (86/80) (line-too-long)
xla/python/xla_client_test.py:3355:0: C0301: Line too long (87/80) (line-too-long)
xla/python/xla_client_test.py:51:0: W0212: Access to a protected member _xla of a client class (protected-access)
xla/python/xla_client_test.py:54:0: W0212: Access to a protected member _xla of a client class (protected-access)
xla/python/xla_client_test.py:64:4: W0212: Access to a protected member _xla of a client class (protected-access)
xla/python/xla_client_test.py:70:8: W0212: Access to a protected member _single_device_array_to_np_array of a client class (protected-access)
xla/python/xla_client_test.py:77:9: W0212: Access to a protected member _device of a client class (protected-access)
@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: