Skip to content

Instantly share code, notes, and snippets.

View ytxmobile98's full-sized avatar

Tianxing Yang ytxmobile98

  • Guangzhou, China
  • 11:29 (UTC +08:00)
View GitHub Profile
@ytxmobile98
ytxmobile98 / find_transformers_num_params.py
Created July 14, 2025 06:06
How to find out the parameter size for a transformers model
from transformers import AutoModel
import torch
model_path = "./my_downloaded_model"
model = AutoModel.from_pretrained(model_path, local_files_only=True)
total_params = sum(p.numel() for p in model.parameters())
trainable_params = sum(p.numel() for p in model.parameters() if p.requires_grad)
print(f"Total parameters: {total_params}")
@ytxmobile98
ytxmobile98 / kill_tree.sh
Created April 1, 2025 01:00
Kill a PID and all its descendants
#!/usr/bin/env bash
function kill_tree {
local pid=$1
local children=$(pgrep -P $pid)
for child in $children; do
kill_tree $child
done
@ytxmobile98
ytxmobile98 / Half The Sky.md
Created March 27, 2025 01:46
Half The Sky Documentary
@ytxmobile98
ytxmobile98 / main.go
Created December 18, 2024 05:51
1000 Goroutines
package main
import (
"fmt"
"runtime"
"sync"
"time"
)
func main() {
@ytxmobile98
ytxmobile98 / Enable-NPU.md
Last active March 6, 2025 15:59
Install OpenVINO using APT on Ubuntu

Reference: https://github.com/intel/linux-npu-driver/releases/tag/v1.8.0

First we need to install the NPU drivers.

  • Ubuntu 24.04

    # 1. wget all the driver deb packages
    wget https://github.com/intel/linux-npu-driver/releases/download/v1.8.0/intel-driver-compiler-npu_1.8.0.20240916-10885588273_ubuntu24.04_amd64.deb
    wget https://github.com/intel/linux-npu-driver/releases/download/v1.8.0/intel-fw-npu_1.8.0.20240916-10885588273_ubuntu24.04_amd64.deb
@ytxmobile98
ytxmobile98 / main.go
Created July 10, 2024 13:12
Multi-level map in Go
package main
var m = map[int]map[int]struct{}{
1: {2: struct{}{}},
}
func main() {
for _, item := range [][2]int{
{1, 2},
{1, 3},
@ytxmobile98
ytxmobile98 / main.go
Last active July 10, 2024 00:24
Go use goroutines to print 1~10
package main
func printN(n int, prev <-chan struct{}, next chan<- struct{}) {
<-prev // wait for the previous signal
println(n)
next <- struct{}{} // activate the next goroutine
}
func printAll(n int) {
if n < 1 {
@ytxmobile98
ytxmobile98 / main.cpp
Created February 29, 2024 03:27
C++ pimpl example
// PIMPL
#include <iostream>
#include <string>
template <typename T>
class Pimpl {
protected:
T *const impl;
public:
Pimpl();
@ytxmobile98
ytxmobile98 / main.cpp
Created February 29, 2024 03:26
C++ member destructor
// Example program
#include <iostream>
#include <memory>
#include <string>
using std::cout;
using std::endl;
using std::make_unique;
using std::unique_ptr;