Skip to content

Instantly share code, notes, and snippets.

View hsqStephenZhang's full-sized avatar
🎯
Focusing

z combinator hsqStephenZhang

🎯
Focusing
View GitHub Profile
@hsqStephenZhang
hsqStephenZhang / test_llama_export.py
Last active July 9, 2026 10:04
torch-mlir export llama
import torch
from transformers import AutoModelForCausalLM, LlamaConfig
import torch_mlir.fx as fx
from torch._subclasses.fake_tensor import FakeTensorMode
from torch.utils._mode_utils import no_dispatch
print("Configuring tiny Llama model...")
config = LlamaConfig(
vocab_size=1000,
hidden_size=128,
@hsqStephenZhang
hsqStephenZhang / triu_e2e_test.md
Last active July 7, 2026 12:00
end to end test for

source

  1. save the following content to path/to/triu.mlir
module {
  func.func @main(%arg0: !torch.vtensor<[4,4],f32>) -> !torch.vtensor<[4,4],f32> {
    %int1 = torch.constant.int 1
    %0 = torch.aten.triu %arg0, %int1 : !torch.vtensor<[4,4],f32>, !torch.int -> !torch.vtensor<[4,4],f32>
    return %0 : !torch.vtensor<[4,4],f32>
@hsqStephenZhang
hsqStephenZhang / iree_24261_flow.mlir
Last active July 6, 2026 14:20
iree issue 24261 generated mlir
module attributes {stream.affinity.default = #hal.device.affinity<@__device_0>} {
util.global private @__device_0 = #hal.device.target<"local", [#hal.executable.target<"llvm-cpu", "embedded-elf-x86_64", {cpu = "generic", cpu_features = "", data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", iree.encoding.resolver = #iree_cpu.cpu_encoding_resolver<>, max_stack_allocation_size = 32768 : i64, native_vector_size = 16 : i64, target_triple = "x86_64-unknown-unknown-eabi-elf"}>]> : !hal.device
flow.executable private @test$async_dispatch_0 {
flow.executable.export public @test$async_dispatch_0_elementwise_broadcast workgroups() -> (index, index, index) {
%c1 = arith.constant 1 : index
flow.return %c1, %c1, %c1 : index, index, index
}
builtin.module {
func.func @test$async_dispatch_0_elementwise_broadcast(%arg0: !iree_tensor_ext.dispatch.tensor<readonly:tensor<2xi64>>, %arg1: !iree_tensor_ext.dispatch.tensor<writeonly:tensor<i64>>) {
import torch
import torch.nn as nn
import iree.turbine.aot as aot
class MinimalSplatModel(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(3, 8, kernel_size=3, stride=1, padding=1)
self.conv1 = nn.Conv2d(3, 8, kernel_size=3, stride=1, padding=1)
self.bn1 = nn.BatchNorm2d(8)
@hsqStephenZhang
hsqStephenZhang / fxhash_std_bench.rs
Created May 16, 2026 19:19
benchmark between fxhash and std hasher for cuda-oxide's String keys
use std::collections::HashMap;
use std::hint::black_box;
use criterion::{BatchSize, BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
use fxhash::FxHashMap;
use fxhash_vs_stdhash::{build_insert_keys, build_lookup_keys};
const ENTRY_COUNT: usize = 100_000;
const LOOKUP_COUNT: usize = 100_000;
const HIT_RATES: &[(u32, usize)] = &[(25, 25_000), (50, 50_000), (75, 75_000)];
@hsqStephenZhang
hsqStephenZhang / torch_decompose_test.py
Created April 30, 2026 13:50
decompose test for torch
import torch
import torch.nn.functional as F
from torch._dynamo.backends.common import aot_autograd
from torch._decomp import get_decompositions
def inspect_compiler(label):
def my_compiler(gm, example_inputs):
print(f"\n=== {label} ===")
for node in gm.graph.nodes:
if node.op == "call_function":
#[cfg(test)]
mod tests {
use crate::{
background::BackgroundLoopChannels,
commands::{SearchJob, SearchOptionsPayload},
};
use crossbeam_channel::{bounded, unbounded};
use search_cache::SearchCache;
use search_cancel::CancellationToken;
use std::{fs, thread, time::Duration};
@hsqStephenZhang
hsqStephenZhang / mpmc_race_repo_test.rs
Last active April 28, 2026 08:34
test case to reproduce the race condition using MSMC channel for search result in cardinal
#[cfg(test)]
mod tests {
use crate::commands::{SearchJob, SearchOptionsPayload};
use crate::background::BackgroundLoopChannels;
use crossbeam_channel::{unbounded, bounded};
use search_cache::{SearchCache, SearchOutcome};
use search_cancel::CancellationToken;
use std::thread;
use std::time::Duration;
use anyhow::Result;
@hsqStephenZhang
hsqStephenZhang / bench-tun.sh
Created April 8, 2026 13:10
benchmark between tun2 and tun-rs
#!/usr/bin/env bash
# bench-offload.sh
#
# Benchmarks netstack-smoltcp's forward example with 2-stream iperf3.
# Compares:
# - tun2 (main branch, no GRO/GSO offload)
# - tun-rs (patched, with Linux GRO/GSO offload via IFF_VNET_HDR)
#
# Setup: creates a veth pair + network namespace; iperf3 server runs inside
# the namespace, the forward proxy bridges traffic through a TUN device.
@hsqStephenZhang
hsqStephenZhang / riscv-debian.md
Created March 5, 2026 17:17 — forked from apivovarov/riscv-debian.md
Run RISC-V Debian via QEMU #riscv #qemu

Run RISC-V Debian GNU/Linux bullseye/sid via QEMU.

  1. Run the latest version of Debian on regular x86_64 box (at least ver 10 Buster, better to run ver 11 Bullseye)
  2. If opensbi and u-boot-qemu packages are not found add testing apt repository (aka bullseye). Or even unstable (aka sid)
sudo vi /etc/apt/sources.list

# Add testing repo (or unstable)
deb http://cdn-aws.deb.debian.org/debian testing main
deb-src http://cdn-aws.deb.debian.org/debian testing main