Skip to content

Instantly share code, notes, and snippets.

View razhangwei's full-sized avatar

Wei Zhang razhangwei

  • Facebook
  • Bay Area
View GitHub Profile
@razhangwei
razhangwei / chat_template.md
Last active September 2, 2024 18:25
chat template

Jinja

Go

Delimiters:

{{ and }} are used to enclose template actions.

Conditionals:

@razhangwei
razhangwei / nf4.py
Created September 2, 2024 17:41
NormalFloat 4 Quantization #pytorch #quantization
import torch
import torch.nn as nn
import torch.nn.functional as F
class NF4Quantizer(nn.Module):
def __init__(self):
super().__init__()
self.nf4_values = torch.tensor([
-1.0, -0.6961928009986877, -0.5250730514526367, -0.39491748809814453,
-0.28444138169288635, -0.18477343022823334, -0.09105003625154495, 0.0,
@razhangwei
razhangwei / cookiecutter
Created September 2, 2024 04:06
cookiecutter #template
1. install with pipx
2. ` pipx run cookiecutter gh:audreyfeldroy/cookiecutter-pypackage`
@razhangwei
razhangwei / pynput_demo.py
Last active August 31, 2024 18:18
pynput example #keyboard #macos #system
from pynput import keyboard
from pynput.keyboard import Key, Controller
# For simulating keyboard presses
keyboard_controller = Controller()
def on_press(key):
try:
print(f'Alphanumeric key pressed: {key.char}')
except AttributeError:
@razhangwei
razhangwei / rope.py
Last active January 2, 2025 00:36
#pytorch RoPE
import math
import torch
import torch.nn as nn
class RotaryPositionEmbedding(nn.Module):
"""
Implements Rotary Position Embedding (RoPE) as a PyTorch module.
Args:
dim (int): Dimension of the embedding (must be even)
@razhangwei
razhangwei / aider.md
Last active February 9, 2025 18:27
#aider #cheetsheat
  • Use .aider.conf.yml
    • to load CONVENTION.md and all reference files.
  • put various API keys ~/.env
  • preferred models:
    • default: DeepSeek C V2
    • More challenging task: Sonet-3.5
  • How to use it for understanding the code
    • /add README and ask
      • "Give me overview of this repo and explain its system design"
  • "Show me how the execution flows"
@razhangwei
razhangwei / open_webui.md
Last active February 16, 2025 04:01
Open WebUI
  • How to use Pipe?

    • Find one on the website and import it.
    • Configure the Valves (paramters), usually just the API key is needed.
    • The Pipe's corresponding model will show up in the model list.
  • Add models

    • Add openrouter api in connection and manually add models so that the default list didn't overwelme
    • Add gemini api in the conneciton, but the model list won't be loaded correctly, so it also needs to manually add models (open-webui/open-webui#8445)
@razhangwei
razhangwei / llm_providers.md
Created August 15, 2024 16:49
LLM Providers
  • API keys
  • Lepton: 3RPT8lpHOSQSvxPrv1wPyBGxPCCKo80L
@razhangwei
razhangwei / obsidian_livesync.md
Last active July 31, 2024 21:36
Obsidian self-hosted livesync

Self-hosted Livesync:

  • paraphrase: test
  • second brain: `obsidian://setuplivesync?settings=%25a4ecc585a55dc1bb885c4b5c650300003837ca8917e2f08d2fc9f06bfe4fa6afFq3qrQffg6yQvnZIemt8cAm%2BfKxsbPJjgmAuHdG8kHG6tNwwPxWGQfFLaXytgVlZoBRe132Ud%2Ba3OxSfWSeeIGfUJeJ6RfBW2lKDTGXb%2F9WMq4TAS6I6jHm1lwW0HrBZ55WHUaDIcQ9NipZCqDUgMtB4N1NDtb59qNyJ6SHqnF2IgWKDxeRa6kdHacRcCJMT5MHhUhmonPxQOUWQJth6zx78dMRH%2FO24%2B4xlkQSVGlgzYSWPYixs0HrNprwh5MV86AzJ2xRJW8CziigIqIm75u%2B648IYwFefyH2XyWjkQO2erb%2FVaEsu4oKqYvhXbYsOp%2Bu3tthXh%2BTLIZMcPf8XuYunAzEJbnMztN8fT17JN0Ju4HaIolE2YwmmO%2FiuqfNFgx602zBW%2Be2aR1xxlIhykHNx7zJpcWtGeSIV3Li15hf%2FXxCd56w%2Bu7q7rcmwkMyWsj1B4T7AlunkFaQRWJyrBXNCVhMPzMTZ6pjmK%2BvgI9PmudxmuBiePvT1iMWL1C2gCJsOPXvYQF34Dhg%2BRXmryAfaQ84ZQd046tCuZ7nGGa3XM3oICAhng1gyFvXIULTEX8WdrDvDA%2BNyYwPv%2BX2Diczpb8ecMiFfNj05vwAe8VY5nLu5iZFIOgv8yLC7PXoMR0pxsRHp%2FjEGxTCcOkDRDwC8inOQHpWNmolx%2BqvDkyl6mxi%2BkjPrReR%2B17VS0HDBtdhJc6F1vH5I3LKfK5pRjz4QUNtLwWhFv9vPkjPGs7N6ndhkOnjjbdFyp%2BcXzYsG2b7SS7%2Bz34umlSV2k3%2FeA9%2F%2BPzuBNA5qBAE5p26YA1
@razhangwei
razhangwei / ip.sh
Last active July 4, 2024 07:39
ip tool #unix
arp = ip neigh
ifconfig = ip addr
route = ip route
netstat = ss
ip addr show name
# Create MacVLan
ip link add mac0 link ens18 type macvlan mode bridge
ip addr add 192.168.0.94/27 dev mac0 # it needs to be subnet of the original macvlan