Skip to content

Instantly share code, notes, and snippets.

View kemingy's full-sized avatar
🈚
actions

Keming kemingy

🈚
actions
View GitHub Profile
@kemingy
kemingy / redis.md
Created September 6, 2020 10:16
redis database

Data Types

https://redis.io/topics/data-types-intro

  • binary-safe strings
  • lists: strings (insertion order) (linked list instead of array)
  • sets: strings
  • sorted sets: (strings, score)
  • hashes: {string:string}
  • bit array: bitmaps
@kemingy
kemingy / vagrant_cluster
Created August 25, 2020 03:44
vagrant config
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
config.vm.define :pd do |pd|
pd.vm.hostname = "pingcap.pd"
pd.vm.network :private_network, ip: "192.168.0.1"
pd.vm.network "forwarded_port", guest: 2379, host: 2379, host_ip: "127.0.0.1"
pd.vm.network "forwarded_port", guest: 3000, host: 3000, host_ip: "127.0.0.1"
pd.vm.network "forwarded_port", guest: 3000, host: 9093, host_ip: "127.0.0.1"
@kemingy
kemingy / subprocess_cmd.py
Created August 20, 2020 11:55
python subprocess cmd signal logging arguments
import logging
import signal
import subprocess
import sys
from pathlib import Path
logger = logging.getLogger(__name__)
def run(filepath):

Training

  • learning rate
  • dropout
  • max token
  • clip norm
  • tokenization method
  • update freq (mini-batch with delayed update)
  • optimizer
  • learning rate scheduler
@kemingy
kemingy / client.py
Last active June 17, 2024 08:49
unix domain socket vs. multiprocessing transfer time
import socket
import numpy as np
import pickle
import time
import struct
matrix = np.random.random((224, 224, 3))
socket_path = './uds.sock'
@kemingy
kemingy / dockerfile.md
Last active July 24, 2020 10:06
dockerfile for production, python
  • from image version FROM python:3.8.5-buster
  • package version fixed in requirements.txt file
  • build cache
  • non-root user
    RUN useradd --create-home appuser
    WORKDIR /home/appuser
    USER appuser
    
  • don't use alpine (slow, bug)
@kemingy
kemingy / multiprocess_pool_init.py
Created July 16, 2020 02:59
python multiprocessing pool process init
import multiprocessing
from time import time
from functools import wraps
def timeit(epoch=1000):
def decorator(func):
@wraps(func)
def wrap(*args, **kw):
ts = time()
@kemingy
kemingy / more.py
Last active July 16, 2020 12:09
global nonlocal variables
x = 233
def xxx():
x = 222
def foo():
nonlocal x
x = 1
@kemingy
kemingy / thread_obj.md
Created July 13, 2020 03:58
Python multithread/multiprocessing object
  • Lock
  • RLock: a reentrant lock
  • Condition:
    • wait: release the lock
    • notify/notify_all
  • Semaphore: manages an internal counter (always non-negative)
  • Event: manages an internal flag (boolean)
  • Timer
  • Barrier: a fixed number of threads that need to wait for each other

Features Required

  • prevent single point faliure
  • batch requests
  • scaling
  • job recovery (retry)

Queue