Skip to content

Instantly share code, notes, and snippets.

@cavit99
cavit99 / beam_search_mlx.py
Created February 22, 2025 03:34
sample beam search decoding with MLX
# 2025 Cavit Erginsoy, MIT License
import time
from typing import Optional
import mlx.core as mx
import mlx.nn as nn
from transformers import AutoTokenizer, AutoConfig
from dataclasses import dataclass
from huggingface_hub import hf_hub_download
import heapq
@cavit99
cavit99 / gist:d8ae5034569d8865ad977dae92308df1
Created February 1, 2025 14:52
Sample system message for building simulating 'reasoning'
Word Ladder puzzles involve transforming a start word into an end word. You are allowed to change only one letter a time and you must keep the number of letters constant.
Each time you change one letter the word in the chain must be forming a new word that's valid in English. Plurals are allowed, but not proper nouns.
Your task will be to simulate a detailed step-by-step chain of thought reasoning of the transformation process from a start word to the end word of a word ladder.
You will be given the word ladder question, as well as the correct solution path. So you don't need to solve the problem, you have the solution already, which should be your 'cheat sheet' to refer to as you go along.
Your task is to provide a perfectly simulated chain of thought reasoning exactly in the style of the example below,
including considering multiple possibilities, backtracking where needed, validating words, and showing the final path.
Remember you're NOT trying to find the shortest path, you're trying to find one path t
@cavit99
cavit99 / qwen2vl.py
Last active April 14, 2025 06:47
Qwen2-VL-7B-Instruct inference on Apple silicon
import torch
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from PIL import Image
from pathlib import Path
import sys
# Toggle to switch between full response and extracted description
OUTPUT_FULL_RESPONSE = False
# Ensure we're using the MPS device if available
@cavit99
cavit99 / sd3_upscale.py
Last active April 18, 2024 10:49
Stability AI API call in python for SD3 + Creative Upscale
import requests
import uuid
import time
import random
api_key = "your-stability-api-key"
num_batches = 6 # Specify the number of images to generate per API
prompt = "Your prompt here"
negative_prompt = "optional negative prompt here" # Optional