Skip to content

Instantly share code, notes, and snippets.

View Maximilian-Winter's full-sized avatar

Maximilian Winter Maximilian-Winter

  • Königswinter
View GitHub Profile
@Maximilian-Winter
Maximilian-Winter / gbnf_grammar_generator.py
Last active April 24, 2024 22:03
GBNF grammar generator for always valid function calls and object creation in JSON with llama.cpp
import inspect
import json
import re
import typing
from inspect import isclass, getdoc
from types import NoneType
from pydantic import BaseModel, Field
from pydantic.fields import FieldInfo
from typing import Any, Type, List, get_args, get_origin, Tuple, Union, Optional
@Maximilian-Winter
Maximilian-Winter / top-k-top-p.py
Created June 10, 2023 19:04 — forked from thomwolf/top-k-top-p.py
Sample the next token from a probability distribution using top-k and/or nucleus (top-p) sampling
def top_k_top_p_filtering(logits, top_k=0, top_p=0.0, filter_value=-float('Inf')):
""" Filter a distribution of logits using top-k and/or nucleus (top-p) filtering
Args:
logits: logits distribution shape (vocabulary size)
top_k >0: keep only top k tokens with highest probability (top-k filtering).
top_p >0.0: keep the top tokens with cumulative probability >= top_p (nucleus filtering).
Nucleus filtering is described in Holtzman et al. (http://arxiv.org/abs/1904.09751)
"""
assert logits.dim() == 1 # batch size 1 for now - could be updated for more but the code would be less clear
top_k = min(top_k, logits.size(-1)) # Safety check
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

How to convert markdown to PDF:

This post reviews several methods for converting a Markdown (.md) formatted file to PDF, from UNIX or Linux machines.

Using Pandoc:

$ pandoc How_I_got_svg-resizer_working_on_Mac_OSX.md -s -o test1.pdf
@Maximilian-Winter
Maximilian-Winter / markdown-text-101.md
Created September 9, 2022 09:12 — forked from matthewzring/markdown-text-101.md
A guide to Markdown on Discord.

Markdown Text 101

Want to inject some flavor into your everyday text chat? You're in luck! Discord uses Markdown, a simple plain text formatting system that'll help you make your sentences stand out. Here's how to do it! Just add a few characters before & after your desired text to change your text! I'll show you some examples...

Sweet Styles

Italics *italics* or _italics_

Underline italics __*underline italics*__

@Maximilian-Winter
Maximilian-Winter / UDPClientUWP.cs
Created May 9, 2018 21:30 — forked from knasa21/UDPClientUWP.cs
HoloLens用UDP受信プログラム(ClientじゃなくてServerかな)
using UnityEngine;
using UnityEngine.Assertions;
using System.Text;
#if UNITY_EDITOR
using System.Net;
using System.Net.Sockets;
#else
using System;
using System.IO;