Skip to content

Instantly share code, notes, and snippets.

View rafaself's full-sized avatar

Rafael rafaself

View GitHub Profile
@rafaself
rafaself / affine_quantization.py
Created October 23, 2026 20:10
Implementation of signed affine quantization and dequantization using NumPy, including scale and zero-point calculation, rounding, clipping, and configurable bit-width.
import numpy as np
def round_away(x):
return np.sign(x) * np.floor(np.abs(x) + 0.5)
def quantize_affine(x, num_bits=8):
x = np.asarray(x, dtype=np.float64)
q_min = -(2 ** (num_bits - 1))
q_max = 2 ** (num_bits - 1) - 1
@rafaself
rafaself / simple-vllm-chat.py
Created October 23, 2026 14:18
A Simple vLLM Chat with a minimal CLI chatbot demonstrating LLM inference, conversation history, system prompts, and output validation.
from vllm import LLM, SamplingParams
# Model configuration
MODEL_NAME = "Qwen/Qwen2.5-0.5B-Instruct"
llm = LLM(model=MODEL_NAME)
# Inference configuration
llm_config = {
"temperature": 0.2,
@rafaself
rafaself / linear_regression_gradient_descent.py
Created October 22, 2026 01:21
Linear regression implemented from scratch in Python using NumPy and Batch Gradient Descent, including MSE loss, analytical gradients, and training visualization.
import numpy as np
import matplotlib.pyplot as plt
x = np.array([0, 1, 2, 3, 4, 5], dtype=float)
y = np.array([1, 3, 5, 7, 9, 11], dtype=float)
m = 0.0
b = 0.0
learning_rate = 0.01
@rafaself
rafaself / file-buffer.js
Created October 11, 2026 19:05
Writing buffers into a file
import { open, readFile } from "node:fs/promises";
async function* createBody() {
yield Buffer.from("Hello");
yield Buffer.from(" ");
yield Buffer.from("World!");
}
async function writeObject(body) {
const handle = await open("example.txt", "w");
@rafaself
rafaself / mini-project-ring-buffer.cpp
Created March 1, 2026 13:39
Mini Project Ring Buffer
#include <array>
#include <cstddef>
#include <iostream>
#include <optional>
template <class T, std::size_t N>
class RingBuffer {
static_assert(N > 0, "N must be > 0");
public: