Skip to content

Instantly share code, notes, and snippets.

"""
Decompose and memorize by program, only asking LLMs to do low-level computations.
"""
import openai
import re
import math
from tenacity import (
retry,
@yuchenlin
yuchenlin / chat_app.py
Last active February 21, 2024 08:40
chat_app.py
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers import StoppingCriteria, StoppingCriteriaList, LogitsProcessor, LogitsProcessorList
model_path = "./qlora-out-hkg_300B/merged/"
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=False, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto", trust_remote_code=True)
@yuchenlin
yuchenlin / Yi-6B-Chat.0-100.json
Created February 28, 2024 04:06
pairrm_dpo_datagen
[
{
"session_id": "7f4abf64593c439f8b085585aeeda566",
"model_input": "<|im_start|>user\nGive me an introduction over 200 words for ShangHai BMG Chemical Co., Ltd, a chemical company in Room 602, no 291 sikai road shanghai Shanghai,China<|im_end|>\n<|im_start|>assistant\n",
"output": [
"ShangHai BMG Chemical Co., Ltd. is a leading chemical company located in Room 602, No. 291 Sikai Road, Shanghai, China. Established in 2010, the company has since been dedicated to providing high-quality chemical products and services to its customers. With a strong R&D team and advanced production facilities, ShangHai BMG Chemical Co., Ltd. has become a trusted partner in the chemical industry, serving a wide range of clients across various sectors. The company's commitment to innovation, quality, and customer satisfaction has enabled it to maintain a competitive edge in the market.",
"ShangHai BMG Chemical Co., Ltd. is a leading chemical company located in Room 602, No. 291 Sikai Road, Shanghai, Chin

ZebraLogic: Benchmarking the Logical Reasoning Ability of Language Models

zebra_banner
image
from transformers import GPT2LMHeadModel, GPT2Tokenizer
import torch
# Test the model before saving
def chat_with_model(model, tokenizer, instruction, max_length=50):
prompt = f"### User: {instruction}\n\n### AI: "
inputs = tokenizer.encode(prompt, return_tensors='pt').to(device)
outputs = model.generate(inputs, max_length=max_length, num_return_sequences=1, top_k=50)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)