Skip to content

Instantly share code, notes, and snippets.

@ayaka14732
ayaka14732 / is_tpu_in_use.py
Created September 19, 2022 06:59
Check if Google Cloud TPU is in use
def is_tpu_in_use() -> bool:
import fcntl
from fcntl import LOCK_EX, LOCK_NB
import posix
from posix import O_CREAT, O_RDWR
import sys
# https://github.com/tensorflow/tensorflow/blob/1a05bad57a2eb870a561daba0255761e0a472d1d/tensorflow/core/tpu/tpu_initializer_helper.cc#L167-L171
fd = posix.open('/tmp/libtpu_lockfile', O_CREAT | O_RDWR, 0o644)
try:
@ayaka14732
ayaka14732 / save_mem.py
Last active January 16, 2024 07:48
Track TPU memory usage while running the training script. See https://twitter.com/ayaka14732/status/1565016471323156481 for more details.
# monitor the memory profile with `watch --color -n1 go tool pprof -tags /dev/shm/memory.prof`
import functools
import jax
import jax.numpy as np
import random
import threading
devices = jax.devices()
n_devices = jax.device_count()
@ayaka14732
ayaka14732 / .gitignore
Last active July 24, 2024 16:21
入声字情感分析:入声字的情感与舒声字无明显差别
/zh_en.linux
/char.csv
/词表.txt
/结果.txt
@ayaka14732
ayaka14732 / gpt2_restricted_generation.py
Created April 10, 2022 12:10
Restricted text generation with Hugging Face GPT-2 model
# Generate texts by only selecting the words that starts with the letter s
import jax
import jax.nn as nn
import jax.numpy as np
import jax.random as rand
import string
from transformers import GPT2Tokenizer, FlaxGPT2LMHeadModel
# filters
@ayaka14732
ayaka14732 / README.md
Last active March 20, 2022 06:58
Visualise a nested Python dictionary by Graphviz

Visualise a nested Python dictionary by Graphviz

Suppose we have a nested Python dictionary like this:

d = {
    'fc1': {'kernel': (768, 3072), 'bias': (3072,)},
    'fc2': {'kernel': (3072, 768), 'bias': (768,)},
    'self_attn': {
        'k_proj': {'kernel': (768, 768), 'bias': (768,)},
We can't make this file beautiful and searchable because it's too large.
小韻號,韻部原貌,ID,原小韻號,頁號,行號,字號,字頭,上字,下字,被切字音韻描述,被切字母,被切字呼,被切字等,被切字重紐,被切字韻,被切字聲,被切字清濁,被切字組,被切字音,被切字攝,上字音韻描述們,上字母們,上字呼們,上字等們,上字重紐們,上字韻們,上字聲們,上字清濁們,上字組們,上字音們,上字攝們,下字音韻描述們,下字母們,下字呼們,下字等們,下字重紐們,下字韻們,下字聲們,下字清濁們,下字組們,下字音們,下字攝們,備註
1,東,1077,w10131,2,27,6,蓬,薄,紅,並一東平,並,x,一,x,東,平,全濁,幫,脣,通,並唐入,並,x,一,x,唐,入,全濁,幫,脣,宕,匣一東平,匣,x,一,x,東,平,全濁,影,喉,通,
2,東,590,w10123,2,20,4,蒙,莫,紅,明一東平,明,x,一,x,東,平,次濁,幫,脣,通,明唐入,明,x,一,x,唐,入,次濁,幫,脣,宕,匣一東平,匣,x,一,x,東,平,全濁,影,喉,通,
3,東,3,w10101,2,11,1,東,德,紅,端一東平,端,x,一,x,東,平,全清,端,舌,通,端開登入,端,開,一,x,登,入,全清,端,舌,曾,匣一東平,匣,x,一,x,東,平,全濁,影,喉,通,
4,東,949,w10129,2,25,8,通,他,紅,透一東平,透,x,一,x,東,平,次清,端,舌,通,透開一歌平,透,開,一,x,歌,平,次清,端,舌,果,匣一東平,匣,x,一,x,東,平,全濁,影,喉,通,
5,東,42,w10102,2,11,3,同,徒,紅,定一東平,定,x,一,x,東,平,全濁,端,舌,通,定模平,定,x,一,x,模,平,全濁,端,舌,遇,匣一東平,匣,x,一,x,東,平,全濁,影,喉,通,
6,東,698,w10124,2,21,8,籠,盧,紅,來一東平,來,x,一,x,東,平,次濁,x,舌,通,來模平,來,x,一,x,模,平,次濁,x,舌,遇,匣一東平,匣,x,一,x,東,平,全濁,影,喉,通,
7,東,995,w10130,2,25,12,葼,子,紅,精一東平,精,x,一,x,東,平,全清,精,齒,通,精之上,精,開,三,x,之,上,全清,精,齒,止,匣一東平,匣,x,一,x,東,平,全濁,影,喉,通,
8,東,893,w10128,2,24,7,怱,倉,紅,清一東平,清,x,一,x,東,平,次清,精,齒,通,清開唐平,清,開
@ayaka14732
ayaka14732 / 廣韻反切音韻地位表(測試版).csv
Created May 21, 2021 01:32
《廣韻》(澤存堂本)反切音韻地位表(測試版)
小韻號 小韻首字 上字 下字 被切字音韻描述們 上字音韻描述們 下字音韻描述們
1 端一東平 端開登入 匣一東平
2 定一東平 定模平 匣一東平
3 知三東平 知開蒸入 見三東平
4 澄三東平 澄開蒸入 見三東平
5 章三東平 章開蒸入 日三東平
6 徹三東平 徹開蒸入 知三東平
7 崇三東平 崇魚平 見三東平
8 心三東平 心開蒸入 見三東平
9 日三東平 日魚平 以三東平
@ayaka14732
ayaka14732 / ie7-virtual-machine-on-windows-vista.md
Last active September 13, 2021 03:56
Download Virtual Machine for Windows Vista (IE7, Linux, VirtualBox version)

The original links (broken)

https://az412801.vo.msecnd.net/vhd/VMBuild_20141027/VirtualBox/IE7/Linux/IE7.Vista.For.Linux.VirtualBox.zip.001
https://az412801.vo.msecnd.net/vhd/VMBuild_20141027/VirtualBox/IE7/Linux/IE7.Vista.For.Linux.VirtualBox.zip.002
https://az412801.vo.msecnd.net/vhd/VMBuild_20141027/VirtualBox/IE7/Linux/IE7.Vista.For.Linux.VirtualBox.zip.003
https://az412801.vo.msecnd.net/vhd/VMBuild_20141027/VirtualBox/IE7/Linux/IE7.Vista.For.Linux.VirtualBox.zip.004
https://az412801.vo.msecnd.net/vhd/VMBuild_20141027/VirtualBox/IE7/Linux/IE7.Vista.For.Linux.VirtualBox.zip.005