Skip to content

Instantly share code, notes, and snippets.

""" Example script for defining and using custom models in AutoGluon Tabular """
from autogluon.core.utils import infer_problem_type
from autogluon.tabular import TabularDataset, TabularPredictor
from autogluon.tabular.configs.hyperparameter_configs import get_hyperparameter_config
from autogluon.core.data import LabelCleaner
from autogluon.core.models import AbstractModel
from skl2onnx import convert_sklearn, get_model_alias
from skl2onnx.common._registration import get_shape_calculator, get_converter
@liangfu
liangfu / example_dev_tabular.py
Last active January 12, 2023 18:54
Benchmark inference time of pretrained AutoGluon Tabular models
# Benchmark inference time of pretrained AutoGluon Tabular models
"""
set -e
DEV_BRANCH=reset-thread-2
git checkout master
/opt/conda/envs/py38/bin/python3 example_dev_tabular.py --sample=1
/opt/conda/envs/py38/bin/python3 example_dev_tabular.py
git checkout $DEV_BRANCH
/opt/conda/envs/py38/bin/python3 example_dev_tabular.py --sample=1
/opt/conda/envs/py38/bin/python3 example_dev_tabular.py
@liangfu
liangfu / mldev.sh
Created January 30, 2023 21:24
Manage AWS EC2 instances with a single-line command
#!/bin/sh
ProgName=$(basename $0)
instance_ids=i-05806fb95d65fffff
region=us-west-2
sub_help(){
echo "Usage: $ProgName <subcommand> [options]\n"
echo "Subcommands:"
echo " start Start mldev instances"
@liangfu
liangfu / mldev_init.sh
Last active July 18, 2023 17:24
Initialize dev workspace with a single bash script
apt update
apt install -y emacs-nox aptitude screen xcscope-el gdb nano || echo 0 && echo "Success"
python3 -m pip install git-remote-codecommit opennmt-tf==1.25.1
cat << EOF > ~/.gdbinit
set print thread-events off
define hook-run
catch throw
end
define hook-quit
import numpy as np
import time
import math
def burn_cpu():
a = np.random.rand(1024, 1024)
b = np.random.rand(1024, 1024)
tic = time.time()
c = np.dot(a, b)
toc = time.time()
@liangfu
liangfu / bedrock.py
Created October 14, 2024 19:17
Ask Bedrock long questions with Python script
import boto3, json
question = """
How are you today?
"""
def main():
session = boto3.Session()
bedrock = session.client(service_name='bedrock-runtime', region_name="us-west-2")
from typing import Any, Dict, List, Optional, Tuple, Type
import torch
import torch_xla.core.xla_model as xm
import torch_xla.experimental.custom_kernel # Required to register custom ops.
class PallasAttentionBackend:
@torch.compile(backend="openxla")
@staticmethod
def copy_blocks(
@liangfu
liangfu / depyf_openxla.py
Created December 2, 2024 23:12
Demonstrate the feasibility of combining depyf with openxla backend
import torch
import torch_xla.core.xla_model as xm
@torch.compile(backend="openxla")
def toy_example(a, b):
x = a / (torch.abs(a) + 1)
if b.sum() < 0:
b = b * -1
return x * b
@liangfu
liangfu / benchmark_xla_scatter.py
Created January 9, 2025 04:34
Benchmark xla scatter with torch-xla
import time
import torch
import torch_xla.core.xla_model as xm
N = 128
n_iters = 100
def main():
device = xm.xla_device()
src = torch.arange(1, 2*N+1).reshape((2, N)).to(device=device)
import torch
import os
import depyf
import torch_xla.core.xla_model as xm
os.environ["NEURON_CC_FLAGS"]= " --model-type=transformer -O1 "
os.environ["NEURON_COMPILE_CACHE_URL"] = os.path.join(os.getcwd(), "_compile_cache")
@torch.compiler.allow_in_graph
def write_to_kv_cache(