Skip to content

Instantly share code, notes, and snippets.

QUESTION:

You are a helpful assistant that solves mazes. You will be given a maze represented by a series of tokens.
The tokens represent:

  • Coordinates: <|row-col|> (e.g., <|0-0|>, <|2-4|>)
  • Walls: <|no_wall|>, <|up_wall|>, <|down_wall|>, <|left_wall|>, <|right_wall|>, <|up_down_wall|>, etc.
  • Origin: <|origin|>
  • Target: <|target|>
  • Movement: <|up|>, <|down|>, <|left|>, <|right|>, <|blank|>

Your task is to output the sequence of movements (<|up|>, <|down|>, <|left|>, <|right|>) required to navigate from the origin to the target, based on the provided maze representation. Think step by step. At each step, predict only the next movement token. Output only the move tokens, separated by spaces.

Question: let say you need to explain how a matrix multiplication work on cpu level from ram to register l1 l2 l3 cache , can you explain step by step with visualization?

Answer: Here's a step-by-step explanation of how matrix multiplication works at the CPU level, including the memory hierarchy (RAM, L1, L2, L3 cache). I'll include visual elements to aid understanding.

1. High-Level Overview:

  • Matrices: Let's consider two matrices A (m x n) and B (n x p). The result will be matrix C (m x p).
  • Operation: The element C[i][j] is calculated as the sum of the products of the elements from the i-th row of A and the j-th column of B: C[i][j] = sum(A[i][k] * B[k][j]) for k = 0 to n-1.
'use client';
import { useState, useRef } from 'react';
import { useChat } from 'ai/react';
export default function Chat() {
const [isRecording, setIsRecording] = useState(false);
const [audioURL, setAudioURL] = useState<string | null>(null);
const mediaRecorderRef = useRef<MediaRecorder | null>(null);
const audioChunksRef = useRef<Blob[]>([]);
@tikikun
tikikun / viet_poem.py
Created August 1, 2024 17:22
Script để crawl thơ việt nam
import requests
from bs4 import BeautifulSoup
import pandas as pd
def fetch_poems(author_name,end_page:int):
"""
Fetch poems from isach.info for a given author.
Args:
author_name (str): Name of the author.
@tikikun
tikikun / ggml-llama-cpp.md
Created May 3, 2024 14:29 — forked from chunhualiao/ggml-llama-cpp.md
Initial source code understanding of ggml (llama.cpp)

I have taken quite some machine learning courses and have done a few projects already. I think I know the math formula involved in transformers and GPT models. However, I always wondered how they work in reality. The best way for me is to read and understand source codes implementing these models. I am a C/C++ programmer mostly. I am more comfortable to read C/C++ programs. So, recently I started to read, run, and debug ggml's gpt-2 inference example since ggml is entirely written in C and can run many transformer models on a laptop: https://github.com/ggerganov/ggml/tree/master/examples/gpt-2 . The famous llama.cpp is closely connected to this library. My experiment environment is a MacBook Pro laptop+ Visual Studio Code + cmake+ CodeLLDB (gdb does not work with my M2 chip), and GPT-2 117 M model. Here is what I have learned so far:

The high-level main function has the following structure https://github.com/ggerganov/ggml/blob/master/examples/gpt-2/main-backend.cpp

  • load the model: ggml specific format us
import * as zlib from 'zlib';
import fetch from 'node-fetch';
// model input params
let prompt = "mdjrny-v4 style 1girl watch at you";
let negative_prompt = "NONE"; // replace NONE with actual negative prompt if any
let samples = 1; // no.of images to generate
let scheduler = "DPMSolverMultistepScheduler";
let steps = 20;
let guidance_scale = 7.5;
import message from './LLM'
const streamToComponent = async (
chatContent: message[],
setTargetText: React.Dispatch<React.SetStateAction<message[]>>
) => {
const url = "https://api.openai.com/v1/chat/completions";
// set initial value for the chat
setTargetText([...chatContent, { role: "", content: "" }]);
import curses
from random import randint
# initialize screen
curses.initscr()
win = curses.newwin(20, 60, 0, 0)
win.keypad(1)
curses.noecho()
curses.curs_set(0)
win.border(0)

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@tikikun
tikikun / compiling_building_c_cpp_notes.md
Created April 7, 2023 07:54 — forked from gubatron/compiling_building_c_cpp_notes.md
Things to remember when compiling and linking C/C++ programs

Things to remember when compiling/linking C/C++ software

by Angel Leon. March 17, 2015;

Updated August 29, 2019.

Updated last on February 27, 2023

Include Paths

On the compilation phase, you will usually need to specify the different include paths so that the interfaces (.h, .hpp) which define structs, classes, constants, and functions can be found.