Skip to content

Instantly share code, notes, and snippets.

View kiyoon's full-sized avatar

Kiyoon Kim kiyoon

View GitHub Profile
@kiyoon
kiyoon / run_tmux_parallel.sh
Last active November 6, 2024 14:34
Run parallel jobs with tmux
# Run multiple commands in a tmux session
script_dir=$(dirname "$(realpath -s "$0")")
if [[ $# -ne 1 ]]; then
sess=session_name
else
sess="$1"
fi
tmux new -d -s "$sess" -c "$script_dir" # Use default directory as this script directory
@kiyoon
kiyoon / xterm_get_mouse_click_and_chars.c
Created December 27, 2023 08:53 — forked from twaik/xterm_get_mouse_click_and_chars.c
Getting mouse clicks on xterm.
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
enum {
KEYSTATE_NONE = 1024,
KEYSTATE_ESCAPE,
KEYSTATE_CONTROL,
KEYSTATE_MOUSE_PROPS
from rich.progress import (
Progress,
ProgressColumn,
SpinnerColumn,
Task,
TextColumn,
TimeElapsedColumn,
)
from rich.text import Text
import tensorrt as trt
import torch
import tqdm
logger = trt.Logger(trt.Logger.WARNING)
runtime = trt.Runtime(logger)
with open("vae_encoder_engine.trt", "rb") as f:
serialized_engine = f.read()
@kiyoon
kiyoon / config.py
Last active February 19, 2024 08:26
Intuitive config system that uses environment variables
# flake8: noqa: D100 D101 D102 D105 T201
from dataclasses import dataclass, field
@dataclass
class BaseConfig:
@property
def envvar_prefix(self) -> str:
return "MLCONFIG_"
@kiyoon
kiyoon / repr_model.py
Last active October 30, 2024 01:55
Print pytorch model with #params and requires_grad information.
# NOTE: __future__ annotations are needed because we want to lazily evaluate torch type hints during runtime.
# Or, you need to wrap the types in quotes, e.g. "torch.nn.Module" instead of torch.nn.Module.
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import torch
@kiyoon
kiyoon / compare_safetensors.py
Created November 15, 2023 04:58 — forked from madebyollin/compare_safetensors.py
script for comparing the contents of safetensors files
#!/usr/bin/env python3
from pathlib import Path
from safetensors.torch import load_file
def summarize_tensor(x):
if x is None:
return "None"
x = x.float()
return f"({x.min().item():.3f}, {x.mean().item():.3f}, {x.max().item():.3f})"
"""
This will make pptx slides containing images.
It assumes your images are square shaped.
"""
from glob import glob
from pptx import Presentation
from pptx.dml.color import RGBColor
from pptx.util import Inches
@kiyoon
kiyoon / awesome-bash-defaults.md
Last active November 30, 2022 17:38
Awesome bash defaults for modern users. Locally install most of the programs.

Configure most of the things without root permission.

Neovim, tmux, Starship, zoxide, fzf, exa, bash vi mode, ...

Shows git stats, command runtime etc. in a nice way.

You can change directory with partial keyword you remember. It will remember the most frequent cd and find it.

@kiyoon
kiyoon / torchvision_models.py
Last active October 4, 2022 23:03
Since torchvision 0.13, models are a little bit difficult to import. This provides backward-compatible function to load models and choose weights. It is also backward-compatible with torchvision < 0.13.
"""
Author: Kiyoon Kim ([email protected])
Since torchvision 0.13 (PyTorch 1.12), the new `weights` parameter is introduced and the original `pretrained` parameter is now deprecated.
It supports more pretrained weights but it is more difficult to find the right one.
This script provides a backward compatible but supporting new version in ease, using strings.
"""
from __future__ import annotations
from typing import Callable, get_type_hints, get_args
from enum import Enum
from packaging import version