Skip to content

Instantly share code, notes, and snippets.

View fpaupier's full-sized avatar
🎲
Focusing

Frαnçois fpaupier

🎲
Focusing
View GitHub Profile
@fpaupier
fpaupier / matrix_rank.py
Created February 25, 2024 15:49
Generate figures of vector space generated from the columns of two 3-dimensions matrix with rank = 3 and rank = 2
import numpy as np
import matplotlib.pyplot as plt
def main() -> None:
# Define the matrices
W1 = np.eye(3) # Identity matrix
W2 = np.array([[3, -2, 1], [2, -2, 0], [0, 1, 1]]) # Rank-deficient matrix
# Create figure for W1
@fpaupier
fpaupier / gpumeter.sh
Created February 13, 2024 06:32
Measure maximum VRAM consumption of a program on linux for Nvidia devices
#!/bin/bash
# Usage ./gpumeter.sh my-gpu-hungry-script.sh
# Check if the command argument is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <script_to_run>"
exit 1
fi
@fpaupier
fpaupier / get_device.py
Created February 11, 2024 09:40
Get torch device
import torch
import subprocess
def get_device():
# Check for CUDA GPU
if torch.cuda.is_available():
return 'cuda'
# Check for Apple Silicon (M1/M2) using sysctl
try:
@fpaupier
fpaupier / test_config_llamacpp.ipynb
Created February 4, 2024 08:03
test_config_llamacpp.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fpaupier
fpaupier / get_courses.sh
Created December 27, 2023 14:18
Download LLM course 11-667 from Carnegie Mellon University
#!/bin/bash
# URL of the website to download from
URL="https://www.andrew.cmu.edu/course/11-667/lectures/"
# Directory where the files will be saved
DESTINATION_DIR="./cmu_course_lectures"
# Create the destination directory
mkdir -p "$DESTINATION_DIR"
@fpaupier
fpaupier / frame_extractor.py
Created October 12, 2021 13:07
Extract frame from a video using ffmpeg and txt file containing a list of timestamps expressed in seconds. One line is a timestamp.
"""
Generates video screenshot from a text file of timestamps expressed in seconds.
Note: ffmpeg must be installed on your machine.
Tested on python3.7
Example usage:
```
@fpaupier
fpaupier / multiprocessing-server-main.py
Created August 8, 2021 10:40
A non working gRPC server init
def main():
"""
Inspired from https://github.com/grpc/grpc/blob/master/examples/python/multiprocessing/server.py
"""
logger.info(f'Initializing server with {NUM_WORKERS} workers')
with _reserve_port() as port:
bind_address = f"[::]:{port}"
logger.info(f"Binding to {bind_address}")
sys.stdout.flush()
workers = []
@fpaupier
fpaupier / faulty-grpc-init.py
Created August 8, 2021 10:19
A Non working gRPC server initialization
import grpc
from concurrent import futures
server = grpc.server(
futures.ProcessPoolExecutor(max_workers=5), # ← HERE: Would be ideal but does not work.
options=[ # See https://github.com/grpc/grpc/issues/14436
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
]
)
@fpaupier
fpaupier / ocr.py
Created August 6, 2021 06:31
OCR over an openCV image with tesseract - extract from https://github.com/fpaupier/gRPC-multiprocessing
def get_text_from_image(img: bytes) -> str:
"""
Perform OCR over an image.
Args:
img (bytes) : a pickled image - encoded with openCV.
Returns:
The text found in the image by the OCR module.
@fpaupier
fpaupier / 740-delete-and-earn.py
Created July 10, 2021 10:10
740. Delete and earn
import collections
class Solution:
def deleteAndEarn(self, nums: List[int]) -> int:
m: int = max(nums)
buckets: List[int] = [0 for _ in range(m+1)]
counter = collections.Counter(nums)
for k, v in counter.items():
buckets[k] = v*k
take, skip = 0, 0