This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
import re | |
ObjType = int | |
class Primitives: | |
[STRING, CHAR, INT, FLOAT, SYMBOL] = range(1, 6) | |
@dataclass | |
class Object: | |
type: ObjType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a simple math expression parser | |
# it solves expressions the way we learned it in math class | |
# and optionally prints the in-between steps | |
# | |
# malformed input produces either ValueError or IndexError | |
# supported are numbers (int, float, complex), parentheses, and operators (+ , - , / , * and ^) | |
# ^ is used for exponents, because ** would be a pain to implement | |
# | |
# licensed under Zero-Clause BSD (https://opensource.org/license/0bsd/) | |
# - silphendio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to use this, first install python and exllamav2 (https://github.com/turboderp/exllamav2) | |
# load a model, rearrange the layers as you like, set generation parameters, and run it | |
# duplicate layers share tensors, but still need extra memory for the cache | |
# thanks to @dnhkng for showing that the cache needs to be re-created | |
# licensed under WTFPL (http://www.wtfpl.net/about/) - Silphendio | |
from exllamav2 import * | |
from exllamav2.generator import * | |
import sys, torch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A simple script to demonstrate the sclicing and recombination of models at runtime | |
# inspired by mergekit | |
# Sadly, it doesn't work with quantisized models. | |
# | |
# public domain - silphendio | |
from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer | |
import torch | |
model_path = 'gpt2' # huggingface name or local folder |