Skip to content

Instantly share code, notes, and snippets.

@liangfu
liangfu / test_sr.py
Created January 17, 2025 23:52
Evaluate stochastic rounding
import os
import time
import torch
import torch_xla.core.xla_model as xm
N = 16
def main():
# os.environ["XLA_USE_BF16"] = "1"
os.environ["NEURON_RT_STOCHASTIC_ROUNDING_EN"] = "1"
@liangfu
liangfu / test_split.py
Last active March 10, 2025 23:45
Evaluate torch.split and slice operator support on openxla backend
import pytest
import torch
import torch_xla.core.xla_model as xm
@pytest.mark.parametrize("batch_size,seq_len,q_size,kv_size", [
(2, 128, 32, 32),
(4, 256, 64, 64),
])
def test_split_consistency(batch_size, seq_len, q_size, kv_size):
# Get XLA device
@liangfu
liangfu / test_split_neuronx.py
Created March 11, 2025 21:26
Evaluate torch.split and slice operator support on openxla backend (with torch_neuronx)
import os
import pytest
import torch
import torch_neuronx
import torch_xla.core.xla_model as xm
@pytest.mark.parametrize("batch_size,seq_len,q_size,kv_size,use_torch_compile,disable_functionalization", [
(2, 128, 32, 32, False, True),
(2, 128, 32, 32, True, True),
(2, 128, 32, 32, False, False),
@liangfu
liangfu / test_mixed_eager_aot.py
Created March 13, 2025 16:34
Evaluate consistency when mixing eager execution with torch.compile()
import torch
import os
import torch_xla.core.xla_model as xm
def write_to_kv_cache(
key: torch.Tensor,
value: torch.Tensor,
key_cache: torch.Tensor,
value_cache: torch.Tensor,
slot_mapping: torch.Tensor,
@liangfu
liangfu / Makefile
Created March 18, 2025 18:44
Rasterization (aka Rendering triangles in framebuffer) in C
# Compiler settings
CC = gcc
CFLAGS = -Wall -Wextra -O2
LDFLAGS = -lm
# Project files
SRC = rasterizer.c
OBJ = $(SRC:.c=.o)
TARGET = rasterizer
@liangfu
liangfu / dot_emacs.el
Created June 5, 2025 00:48
Configure emacs to use gptel with Sonnet-3.7 on Bedrock
;; Configure emacs to use gptel with Sonnet-3.7 on Bedrock
(add-to-list 'load-path "/home/ubuntu/workspace/gptel")
(setq gptel-use-curl "/home/ubuntu/miniconda3/envs/py310/bin/curl")
(setq
gptel-model 'claude-3-7-sonnet-20250219
gptel-backend (gptel-make-bedrock "AWS"
:region "us-west-2"
;; subset of gptel--bedrock-models
:models '(claude-3-7-sonnet-20250219)
;; optional for provisioned access