Skip to content

Instantly share code, notes, and snippets.

View crazyguitar's full-sized avatar
🎯
Focusing

CHANG-NING TSAI crazyguitar

🎯
Focusing
View GitHub Profile
@crazyguitar
crazyguitar / bench.py
Created June 15, 2024 02:06 — forked from marians/bench.py
Benchmarking serialization/unserialization in python using json, pickle and cPickle
import cPickle
import pickle
import json
import random
from time import time
from hashlib import md5
test_runs = 1000
def float_list():
@crazyguitar
crazyguitar / commands.md
Created June 11, 2024 20:13 — forked from mcarilli/commands.md
Single- and multiprocess profiling workflow with nvprof and NVVP (Nsight Systems coming soon...)

Ordinary launch commands (no profiling):

Single-process:

python main_amp.py -a resnet50 --b 224 --deterministic --workers 4 --opt-level O1 ./bare_metal_train_val/

Multi-process:

python -m torch.distributed.launch  --nproc_per_node=2 main_amp.py -a resnet50 --b 224 --deterministic --workers 4 --opt-level O1 ./bare_metal_train_val/

Often, there's a misconception about the Global Interpreter Lock (GIL) in Python, where it's believed that the Python interpreter only permits one thread to run at any given time. Infact, Python Interpreter allows threads running in parallel when GIL is released in a function. For instance, functions like time.sleep leverage I/O blocking within Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS, enabling the Python interpreter to handle multiple threads simultaneously in such cases.

reference:

  1. pysleep

The provided reference demonstrates how Python allows sleep operations to run in parallel:

@crazyguitar
crazyguitar / CUDA-12-1-1-pytorch.md
Created April 10, 2024 21:33 — forked from Birch-san/CUDA-12-1-1-pytorch.md
Installing CUDA 12.1.1 + PyTorch nightly + Python 3.10 on Ubuntu 22.10

Installing CUDA 12.1.1 + PyTorch nightly + Python 3.10 on Ubuntu 22.10

Should you keep your NVIDIA driver?

CUDA 12.1.1 toolkit is gonna offer to install Nvidia driver 530 for us. It's from New Feature branch. It's likely to be newer than the default Nvidia driver you would've installed via apt-get (apt would prefer to give you 525, i.e. Production Branch).

If you're confident that you already have a new enough Nvidia driver for CUDA 12.1.1, and you'd like to keep your driver: feel free to skip this "uninstall driver" step.

But if you're not sure, or you know your driver is too old: let's uninstall it. CUDA will install a new driver for us later.

@crazyguitar
crazyguitar / example.c
Created April 4, 2024 15:23 — forked from plebioda/example.c
libfabric example
#include <rdma/fabric.h>
#include <rdma/fabric.h>
#include <rdma/fi_endpoint.h>
#include <rdma/fi_cm.h>
#include <rdma/fi_errno.h>
#include <rdma/fi_rma.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
@crazyguitar
crazyguitar / gist:d86c83645088cc829752d288a5763f39
Created November 28, 2023 04:34 — forked from arbabnazar/gist:6b9909cfba52ac066512ba5d1c1a1080
Example for Ansible git-module and ssh agent forwarding
# files/env:
Defaults env_keep += "SSH_AUTH_SOCK"
# tasks/main.yml
- name: ensure sudo keeps SSH_AUTH_SOCK in environment
copy: src=env
dest=/etc/sudoers.d/env
mode=0440
owner=root
group=root
@crazyguitar
crazyguitar / ssh_forwarding_cheatsheet.md
Created November 27, 2023 17:32 — forked from jezeniel/ssh_forwarding_cheatsheet.md
SSH Agent Forwarding cheatsheet

Using the ssh agent

The following would show a similar output if a key is already added to your agent, and you are good to go.

$ ssh-add -l
2048 d7:8e:3d:03:9c:4f:f8:9d:04:0f:11:c5:24:e1:2f:3a rsa w/o comment (RSA)

The following will show if no agent is running.

@crazyguitar
crazyguitar / MacOSX_ssh_forwarding.md
Created October 12, 2023 20:30 — forked from gwarf/MacOSX_ssh_forwarding.md
Using ssh forwarding (Agent and X11) on MacOS X

SSH Forwarding on MacOS X

Forwarding SSH agent

Configure ~/.ssh/config

# Allow Agent forwarding for a specific host (by security)
Host remotehost
  ForwardAgent yes
@crazyguitar
crazyguitar / README.md
Created August 17, 2023 23:35 — forked from P4UL-M/README.md
Changing playback sound speed in realtime with python and multiprocessing

Changing playback sound speed in realtime with python and multiprocessing

This is a script to change the sound speed in real time like for example background music in pygame.

The script generates the raw data of a sound file each time there is space in the queue. The sample will scale to the desired speed which you can modify with sound_Factor.

To play the music, you just need to get buffers from the queue and pass them to your music stream. Exemple for pygame :

# musique update
if channel.get_queue() == None: