Skip to content

Instantly share code, notes, and snippets.

@Ronsor
Ronsor / rwkv_simple.py
Last active February 29, 2024 01:48
`mamba_simple` style RWKV implementation
# Copyright © 2024 Ronsor Labs. All rights reserved
# Except as otherwise indicated, you may only use this software in accordance with
# the MIT license.
# A self-contained RWKV-6 x060 implementation, inspired by mamba_simple.
# TimeMix and wkv_op_torch adapted from Apache-2.0-licensed:
# - https://github.com/SmerkyG/gptcore/blob/main/model/experimental/rwkv6_0.py
# - https://github.com/SmerkyG/gptcore/blob/main/model/experimental/rwkv_inner.py
# - https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v5/src/model.py
# No guarantees of correctness are made. You'll still have to do proper initialization
@Ronsor
Ronsor / amalgamate.sh
Created November 30, 2023 19:57
Script to amalgamate GGML into a single-file (source + header) library.
#!/bin/sh
# License: 0BSD, Copyright (C) 2023 Ronsor Labs.
# Usage: ./amalgamate.sh path/to/ggml/repo
GGML_SRC_H='ggml-impl.h ggml-backend-impl.h ggml-quants.h'
GGML_SRC_C='ggml.c ggml-backend.c ggml-quants.c ggml-alloc.c'
GGML_INC_H='ggml.h ggml-alloc.h ggml-backend.h'
ONE_SRC=ggml_one.c
ONE_HDR=ggml_one.h
@Ronsor
Ronsor / retention.py
Created August 2, 2023 03:32
Multiscale Retention (PyTorch)
# PyTorch implementation of Multiscale Retention
# Copyright (C) 2023 Ronsor Labs. This software is licensed to you under the terms of the
# Free Development Public License 1.0 as published at <https://freedevproject.org/fdpl-1.0>.
import torch
from torch import nn, Tensor
from torch.nn import functional as F
class XPos(nn.Module):
def __init__(self, dim: int, theta: int = 10000, scale_base: int = 512):

Keybase proof

I hereby claim:

  • I am ronsor on github.
  • I am ronsor (https://keybase.io/ronsor) on keybase.
  • I have a public key ASDiFtq3AoEdl_eBGfQYlwf7IyR6NrQzabIVzS_qEYTItAo

To claim this, I am signing this object:

@Ronsor
Ronsor / button.html
Created October 22, 2017 14:30
css button styles
<button class=toolbtn>Hello World</button>
<style>
.toolbtn {
background: linear-gradient(180deg, #fefefe 65%, #eeeeee); border-radius: 4px; padding: 5px; padding-left: 10px; padding-right: 10px; border: 1px solid #aaaaaa;
box-shadow: 0px 1px 1px #aaaaaa;
}
</style>
@Ronsor
Ronsor / pow.go
Created September 18, 2017 16:00
proof of work
package main
import "crypto/sha512"
import "crypto/rand"
import "encoding/hex"
import "strings"
import "strconv"
func HashHex(data string) string {
d := sha512.Sum512([]byte(data))
return hex.EncodeToString(d[:])
}
@Ronsor
Ronsor / routing.c
Created July 19, 2017 20:53
simple routing protocol
//gcc 5.4.0
#include <stdio.h>
#include <stdint.h>
#define MAXRT 64
#define NO_TRY
uint64_t me_id = 0xFFEEDDCC;
struct rtable {
uint64_t id;
uint64_t mask;
@Ronsor
Ronsor / malloc.c
Created June 24, 2017 11:11
Simple malloc
#define USED 1
typedef struct {
unsigned size;
} UNIT;
typedef struct {
UNIT* free;
UNIT* heap;
} MSYS;