๐Ÿ‘‹ Welcome to my Blog

๐Ÿ’ป Written for tech.

LLM Funcation Calling with vLLM

Python ENV dependency Run pip install poetry==1.8.0 to install Poetry, which is Python packaging and dependency management tool. openai = "^1.30.3" fastapi = "^0.111.0" transformers = "^4.41.1" tiktoken = "^0.6.0" torch = "^2.3.0" sse-starlette = "^2.1.0" sentence-transformers = "^2.7.0" sentencepiece = "^0.2.0" accelerate = "^0.30.1" pydantic = "^2.7.1" timm = "^1.0.3" pandas = "^2.2.2" vllm = "^0.4.2" vLLM(<=0.4.2) not support tool_call This codes is the best way for tool_call. from openai import OpenAI client = OpenAI() messages = [{"role": "user", "content": "What's the weather like in San Francisco, Tokyo, and Paris?"}] tools = [...] response = client.chat.completions.create( model="gpt-4o", messages=messages, tools=tools, tool_choice="auto", # auto is default, but we'll be explicit ) response_message = response.choices[0].message tool_calls = response_message.tool_calls Due to latest vLLM does not support using tool_call with OpenAI python SDK, releated PR #3237. We will use corresponding model Prompt, then insert tools into request....

Date: June 5, 2024 | Estimated Reading Time: 2 min | Author: Simon Wei

Fine-Tuning BERT for Text classification

Relevant Paper BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding How to Fine-Tune BERT for Text Classification? Fine-Tuning BERT procedure Prepare dataset Load Pre-trained BERT model Load BERT model Tokenizer Define optimizer and hyperparameters Fine-Tuninng step Forward pass: get output for BERT model with target input data. Resets the gradients: clear out the gradients in the previous pass. Backward pass: calculate loss. Parameter update: update parameters and take a step using the computed gradient. Eval model Save best model (checkpoint) PyTorch train import argparse import datetime import os import random import time import warnings import numpy as np import pandas as pd import torch from loguru import logger from torch.utils.data import DataLoader, RandomSampler, TensorDataset, random_split from tqdm.auto import tqdm from transformers import ( AdamW, BertForSequenceClassification, BertTokenizer, get_linear_schedule_with_warmup, ) warnings.filterwarnings("ignore") parser = argparse.ArgumentParser() parser.add_argument("--epoch", type=int) args = parser.parse_args() if torch.cuda.is_available():...

Date: April 10, 2024 | Estimated Reading Time: 4 min | Author: Simon Wei