Skip to content

Instantly share code, notes, and snippets.

@pcuenca
pcuenca / vscode-launch.json
Created August 11, 2024 12:58
Debug Rust dylib from Python script in Visual Studio Code
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
// To debug a Rust dylib (tiktoken) from a Pyton script:
// - Launch the Python script with the Python debugger and stop at a breakpoint.
// - Get the process id (for example, `os.getpid()`)
@pcuenca
pcuenca / gemma-tokenizer-test.ipynb
Created May 8, 2024 15:10
Gemma Tokenizer Tests
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pcuenca
pcuenca / openelm-coreml.py
Created April 30, 2024 09:55
Convert OpenELM to Core ML (float32)
import argparse
import numpy as np
import torch
import torch.nn as nn
import coremltools as ct
from transformers import AutoTokenizer, AutoModelForCausalLM
# When using float16, all predicted logits are 0. To be debugged.
compute_precision = ct.precision.FLOAT32
compute_units = ct.ComputeUnit.CPU_ONLY
@pcuenca
pcuenca / models.sh
Created March 19, 2024 17:28
Retrieve Hugging Face models in the mlx-community organization
curl -s -X GET "https://huggingface.co/api/models?author=mlx-community" | jq ".[].id"
@pcuenca
pcuenca / hub_snippet.py
Created January 3, 2024 20:28
Upload with model card
def upload_to_hub(path: str, name: str, hf_path: str):
import os
from huggingface_hub import HfApi, logging, ModelCard
repo_id = f"mlx-community/{name}"
card = ModelCard.load(hf_path)
card.data.tags = ["mlx"] if card.data.tags is None else card.data.tags + ["mlx"]
card.text = f"""
# {name}
@pcuenca
pcuenca / saya_lcm.py
Created November 9, 2023 11:22
Sayak's LCM benchmark, modified
import torch
import torch.utils.benchmark as benchmark
import argparse
from diffusers import DiffusionPipeline, LCMScheduler
PROMPT = "close-up photography of old man standing in the rain at night, in a street lit by lamps, leica 35mm summilux"
MODEL_ID = "stabilityai/stable-diffusion-xl-base-1.0"
LORA_ID = "lcm-sd/lcm-sdxl-lora-huber-final"
@pcuenca
pcuenca / parse.cs
Created September 5, 2023 18:27
dotnet dynamic property wrapper
using Newtonsoft.Json.Linq;
using System.Dynamic;
using System.Text.RegularExpressions;
public class CamelToSnakeDynamicWrapper : DynamicObject
{
private readonly JObject _jObject;
public static string CamelToSnake(string camelCase)
@pcuenca
pcuenca / mps-self-hosted.md
Created May 17, 2023 09:33
Set up Mac self-hosted CI runner on AWS

Amazon EC2:

  • Create a Dedicated Host. Wait for it to become "Available".
  • Select the host. Click "Actions" and select "Launch instance(s) onto host".
  • Create the instance (Ventura on arm). Attach a secondary drive to be used as hub cache. I chose 1.5 TB.
  • Connect to the instance when it's ready

Mac VM:

  • Enable vnc access
    sudo defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool false\n
@pcuenca
pcuenca / torch2_benchmark.ipynb
Last active March 11, 2023 11:46
Plot benchmark
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pcuenca
pcuenca / MakeContiguousKernel.metal
Created July 29, 2022 12:29
Metal Kernel to make a contiguous copy of MLMultiArray storage
//
// MakeContiguousKernel.metal
//
// Created by Pedro Cuenca on 20220307.
// Copyright © 2022 LateNiteSoft S.L. All rights reserved.
//
#include <metal_stdlib>
using namespace metal;