Skip to content

Instantly share code, notes, and snippets.

View Keith-Hon's full-sized avatar
👋
Hello!

Keith Hon Keith-Hon

👋
Hello!
View GitHub Profile
@Keith-Hon
Keith-Hon / gist:49594ef8a26379fcc46cf5c11c7cf3f2
Created June 27, 2024 05:28
Realtime WebSocket Audio Streamin
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Realtime WebSocket Audio Streaming</title>
<style>
body {
background-color: black;
color: green;
}
@Keith-Hon
Keith-Hon / preprocessed_brands.json
Created September 21, 2022 14:48
preprocessed brands
[
"at t",
"molecole",
"enquiret",
"fairphone",
"ラスタバナナ",
"dcenta",
"caoy",
"sonim",
"jensa",
## Imports
from typing import Tuple
import torch
from torch import Module, Tensor
from transformers.models.roberta.modeling_roberta import RobertaPreTrainedModel, RobertaConfig, RobertaModel, RobertaEncoder
from torch.nn import CrossEntropyLoss, CosineEmbeddingLoss
## Function
@Keith-Hon
Keith-Hon / google_taxonomy_parser.py
Created July 30, 2022 13:24
Python parser for google taxonomy
import requests
en_content = requests.get('https://www.google.com/basepages/producttype/taxonomy-with-ids.en-US.txt')
def load_taxonomy_hierarchy(root, taxonomy_content, is_root):
lines = taxonomy_content.split('\n')
filtered_lines = lines[1:]
filtered_lines = list(filter(lambda line: len(line) > 0, filtered_lines))
# extract the root taxonomy from content
root_taxonomy_set = set()
@Keith-Hon
Keith-Hon / gist:3e8bcf998d8aeae0f1f41f19a7d1f409
Last active April 8, 2022 10:00
Reset k8s for master and work nodes if pod-network-cidr changed
kubeadm reset
## master only
etcdctl rm --recursive registry
rm -rf /var/lib/cni
rm -rf /run/flannel
rm -rf /etc/cni
@Keith-Hon
Keith-Hon / gist:ed48526c3d9a249d5d56048df6172762
Created February 15, 2022 03:36
Github webhook handler for Next.js
// pages/api/webhooks/github.js
const { exec } = require("child_process");
const crypto = require("crypto");
// Handle GitHub Webhooks
export default function handler(req, res) {
try {
console.log("Incoming Request");
if (req.method !== 'POST') {
res.send(404);
@Keith-Hon
Keith-Hon / gist:0098bd40a208de2dc9217df457584845
Created January 10, 2022 10:10
Recursively rename files in windows 10
forfiles /S /M *.ext1 /C "cmd /c rename @file @fname.ext2"
@Keith-Hon
Keith-Hon / gist:e2c3a1f41ed6afd73f0c85b668e58e1a
Created December 31, 2021 09:25
install ngrok in ubuntu
apt install wget
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.tgz
tar xvzf ngrok-stable-linux-amd64.tgz -C /usr/local/bin
@Keith-Hon
Keith-Hon / jserv.py
Created December 31, 2021 01:54 — forked from kinoc/jserv.py
Simplest FastAPI endpoint for EleutherAI GPT-J-6B
# Near Simplest Language model API, with room to expand!
# runs GPT-J-6B on 3090 and TITAN and servers it using FastAPI
# change "seq" (which is the context size) to adjust footprint
#
# seq vram usage
# 512 14.7G
# 900 15.3G
# uses FastAPI, so install that
# https://fastapi.tiangolo.com/tutorial/
@Keith-Hon
Keith-Hon / j6b_train_hf_ds.py
Created December 31, 2021 01:51 — forked from kinoc/j6b_train_hf_ds.py
So now you want to finetune that GPT-J-6B on a 3090/TITAN GPU ... okay, using HF and DeepSpeed too
# So now you want to finetune that GPT-J-6B on a 3090/TITAN GPU ... okay
# More exploratory coding. It uses the Huggingface model port, deepspeed and reads all text/md files from a target directory
# It is a fragment of a larger system with remote editing, but that's another story
# This is the raw, training tester. Items to look out for:
# - uses DeepSpeed and has a DS config
# - to save space uses SGD instead of ADAM
# - uses gradient checkpointing
# - freezes 25% of the layers to fit
# Assumes you can already run https://gist.github.com/kinoc/2d636a68876cd3de7b6e9c9452b61089