Skip to content

Instantly share code, notes, and snippets.

View Birch-san's full-sized avatar

Birch-san

View GitHub Profile
@Birch-san
Birch-san / jit__threefry_split.py
Created June 18, 2022 17:14
MHLO program which compiles on mainline IREE, but which fails to compile on my local install of commit https://github.com/Birch-san/iree/commits/scatter
from iree import compiler
CODE = """
#loc0 = loc(unknown)
module @jit__threefry_split.11 {
func.func public @main(%arg0: tensor<2xui32> loc(unknown)) -> tensor<2x2xui32> {
%0 = "mhlo.iota"() {iota_dimension = 0 : i64} : () -> tensor<4xui32> loc(#loc1)
%1 = "mhlo.slice"(%arg0) {limit_indices = dense<1> : tensor<1xi64>, start_indices = dense<0> : tensor<1xi64>, strides = dense<1> : tensor<1xi64>} : (tensor<2xui32>) -> tensor<1xui32> loc(#loc2)
%2 = "mhlo.reshape"(%1) : (tensor<1xui32>) -> tensor<ui32> loc(#loc3)
%3 = "mhlo.slice"(%arg0) {limit_indices = dense<2> : tensor<1xi64>, start_indices = dense<1> : tensor<1xi64>, strides = dense<1> : tensor<1xi64>} : (tensor<2xui32>) -> tensor<1xui32> loc(#loc4)
@Birch-san
Birch-san / scatter.py
Created June 18, 2022 16:42
compile scatter on iree/vulkan
# see https://github.com/google/iree/issues/9361,
# https://github.com/google/iree/pull/9378
from iree import compiler, runtime as rt
rt.flags.parse_flags("--task_topology_group_count=8")
CODE = """
#loc0 = loc(unknown)
module @jit_prim_fun.12 {
func.func public @main(%arg0: tensor<1x1xi32> loc(unknown), %arg1: tensor<1xi32> loc(unknown), %arg2: tensor<1xi32> loc(unknown)) -> tensor<1x1xi32> {
@Birch-san
Birch-san / compile.sh
Last active June 19, 2022 16:39
Compiling IREE from source on macOS
# https://google.github.io/iree/building-from-source/getting-started/#reference-pages
# https://github.com/google/iree/blob/main/docs/developers/get_started/cmake_options_and_variables.md
git clone --branch scatter --depth 1 https://github.com/Birch-san/iree.git
git submodule update --init
cd iree
pip install pybind11
export CMAKE_OSX_ARCHITECTURES="arm64"
export MACOSX_DEPLOYMENT_TARGET=11.0
export IREE_ENABLE_CPUINFO=OFF
export IREE_HAL_DRIVER_VULKAN=ON
@Birch-san
Birch-san / run.py
Last active July 29, 2023 20:07
Running inferences on cene's imagen-pytorch on-CPU (e.g. on M1 macOS)
import torch as th
from itertools import tee
from PIL import Image
from IPython.display import display
from imagen_pytorch.model_creation import create_model_and_diffusion as create_model_and_diffusion_imagen
from imagen_pytorch.model_creation import model_and_diffusion_defaults as model_and_diffusion_defaults_imagen
from imagen_pytorch.train_all import _fix_path

Installing & running cene's imagen-pytorch

Install Anaconda via command-line arm64 installer

Install PyTorch nightly (to get M1 GPU support)

conda update -n base -c defaults conda
conda create -n torch-nightly python=3.9
pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
@Birch-san
Birch-san / Downscale algorithms compared.md
Created June 13, 2022 22:56
Round-trip restoration of detail from downsampled images

1400x2000 -> 45x64 -> 180x256

(Downscale via traditional algorithm, upscale via AI)

Upscaling of images via Real-ESRGAN, compared by the algorithm via which they were downscaled:

Bilinear:
image
image

@Birch-san
Birch-san / launch.md
Last active June 6, 2022 22:14
how I encountered error running dalle-playground

VSCode launched dalle-playground's backend/app.py Python process like so:

dalle-playground git:(main) ✗  cd /Users/birch/git/dalle-playground
/usr/bin/env /Users/birch/anaconda3/envs/torch-nightly/bin/python /Users/birch/.vscode/extensions/ms-python.python-2022.6.3/pythonFiles/lib/python/debugpy/launcher 52337 -- /Users/birch/git/dalle-playground/backend/app.py 8080 

Using the following launch.json:

@Birch-san
Birch-san / stack.txt
Created June 6, 2022 22:02
stack trace from attempting to run dalle-playground on M1 GPU with jax/jaxlib 345cc19949273cc414d94e6f13d0620b780af465, iree candidate-20220606.161
Error invoking IREE compiler tool iree-compile
Diagnostics:
/Users/birch/anaconda3/envs/torch-nightly/lib/python3.9/site-packages/transformers/models/bart/modeling_flax_bart.py:926:1: error: failed to legalize operation 'mhlo.scatter' that was explicitly marked illegal
input_ids = input_ids.at[(..., -1)].set(self.config.eos_token_id)
^
compilation failed
Invoked with:
iree-compile /Users/birch/anaconda3/envs/torch-nightly/lib/python3.9/site-packages/iree/compiler/tools/../_mlir_libs/iree-compile - --iree-input-type=mhlo --iree-vm-bytecode-module-output-format=flatbuffer-binary --iree-hal-target-backends=vulkan --iree-mlir-to-vm-bytecode-module --iree-llvm-embedded-linker-path=/Users/birch/anaconda3/envs/torch-nightly/lib/python3.9/site-packages/iree/compiler/tools/../_mlir_libs/iree-lld --mlir-print-debuginfo --mlir-print-op-on-diagnostic=false --iree-llvm-target-triple=arm64-apple-darwin21.5.0 --iree-flow-demote-i64-to-i32 --iree-vulkan-target-triple=m1-moltenvk-macos --iree-llvm-target-cpu-featur
@Birch-san
Birch-san / build.out.txt
Created February 14, 2022 00:03
JUCE 6.1.5 fails to compile x86 audio plugin via llvm-mingw
[ 25%] Building CXX object CMakeFiles/AudioPluginExample.dir/linux_native/include/JUCE-6.1.5/modules/juce_gui_basics/juce_gui_basics.cpp.obj
/opt/llvm-mingw/bin/i686-w64-mingw32-clang++ -DDEBUG=1 -DJUCE_GLOBAL_MODULE_SETTINGS_INCLUDED=1 -DJUCE_MODULE_AVAILABLE_juce_audio_basics=1 -DJUCE_MODULE_AVAILABLE_juce_audio_devices=1 -DJUCE_MODULE_AVAILABLE_juce_audio_formats=1 -DJUCE_MODULE_AVAILABLE_juce_audio_processors=1 -DJUCE_MODULE_AVAILABLE_juce_audio_utils=1 -DJUCE_MODULE_AVAILABLE_juce_core=1 -DJUCE_MODULE_AVAILABLE_juce_data_structures=1 -DJUCE_MODULE_AVAILABLE_juce_events=1 -DJUCE_MODULE_AVAILABLE_juce_graphics=1 -DJUCE_MODULE_AVAILABLE_juce_gui_basics=1 -DJUCE_MODULE_AVAILABLE_juce_gui_extra=1 -DJUCE_SHARED_CODE=1 -DJUCE_STANDALONE_APPLICATION=JucePlugin_Build_Standalone -DJUCE_USE_CURL=0 -DJUCE_VST3_CAN_REPLACE_VST2=0 -DJUCE_WEB_BROWSER=0 -DJucePlugin_AAXCategory=0 -DJucePlugin_AAXDisableBypass=0 -DJucePlugin_AAXDisableMultiMono=0 -DJucePlugin_AAXIdentifier=com.yourcompany.AudioPluginExample -DJucePlugin_
@Birch-san
Birch-san / build.out.txt
Created February 13, 2022 23:48
JUCE 6.1.5 compilation failure on llvm-mingw 20220209
[ 25%] Building CXX object CMakeFiles/AudioPluginExample.dir/linux_native/include/JUCE-6.1.5/modules/juce_gui_basics/juce_gui_basics.cpp.obj
/opt/llvm-mingw/bin/x86_64-w64-mingw32-clang++ -DDEBUG=1 -DJUCE_GLOBAL_MODULE_SETTINGS_INCLUDED=1 -DJUCE_MODULE_AVAILABLE_juce_audio_basics=1 -DJUCE_MODULE_AVAILABLE_juce_audio_devices=1 -DJUCE_MODULE_AVAILABLE_juce_audio_formats=1 -DJUCE_MODULE_AVAILABLE_juce_audio_processors=1 -DJUCE_MODULE_AVAILABLE_juce_audio_utils=1 -DJUCE_MODULE_AVAILABLE_juce_core=1 -DJUCE_MODULE_AVAILABLE_juce_data_structures=1 -DJUCE_MODULE_AVAILABLE_juce_events=1 -DJUCE_MODULE_AVAILABLE_juce_graphics=1 -DJUCE_MODULE_AVAILABLE_juce_gui_basics=1 -DJUCE_MODULE_AVAILABLE_juce_gui_extra=1 -DJUCE_SHARED_CODE=1 -DJUCE_STANDALONE_APPLICATION=JucePlugin_Build_Standalone -DJUCE_USE_CURL=0 -DJUCE_VST3_CAN_REPLACE_VST2=0 -DJUCE_WEB_BROWSER=0 -DJucePlugin_AAXCategory=0 -DJucePlugin_AAXDisableBypass=0 -DJucePlugin_AAXDisableMultiMono=0 -DJucePlugin_AAXIdentifier=com.yourcompany.AudioPluginExample -DJucePlugi