Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions configs/inference/Qwen32B/qwen32B.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name_model = "Qwen32B"
max_samples = 32
batch_size = 32
#cpu_offload_gb = 300.0
#cpu_offload_percentage = 0.5
tp = "all"
dataset = "justus27/test-vcu"

[sampling_params]
temperature = 0.7
top_p = 0.95
max_tokens = 100
presence_penalty = 0.1
frequency_penalty = 0.1
Comment thread
apaz-cli marked this conversation as resolved.
Resolved
11 changes: 10 additions & 1 deletion configs/inference/debug.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
name_model = "debugmodel"
max_samples = 32
batch_size = 8
dataset = "justus27/test-vcu"
sample_per_file = 32
dataset = "justus27/test-vcu"

[sampling_params]
temperature = 0.7
top_p = 0.95
max_tokens = 100
presence_penalty = 0.1
frequency_penalty = 0.1
logprobs = None
Comment thread
apaz-cli marked this conversation as resolved.
Resolved
14 changes: 14 additions & 0 deletions configs/training/Qwen32B/qwen32B.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name_model = "Qwen32B"
project = "debug_1B_zero_band"

[train]
micro_bs = 32
reshard_after_forward = true

[optim]
batch_size = 1024
warmup_steps = 1000
total_steps = 8192

[optim.optim]
lr = 7e-4
40 changes: 38 additions & 2 deletions src/zeroband/inference.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import psutil
from pathlib import Path
from typing import Literal
import uuid
import torch
from vllm import LLM, SamplingParams
Expand All @@ -17,16 +19,33 @@
import pyarrow.parquet as pq


class SamplingParamConfig(BaseConfig):
temperature: float = 0.7
top_p: float = 0.95
top_k: int = -1
use_beam_search: bool = False
stop: str | list[str] | None = None
ignore_eos: bool = False
max_tokens: int = 512
presence_penalty: float = 0.1
frequency_penalty: float = 0.1
logprobs: int | None = None


class Config(BaseConfig):
name_model: ModelName = "150M"
dataset: str = "justus27/test-vcu"
batch_size: int = 32
max_samples: int | None = None
output_path: str = "outputs"
tp: int = 1
tp: int | Literal["all"] = 1
max_seq_len: int | None = None
cpu_offload_gb: float = 0.0
cpu_offload_percentage: float = 0.0
Comment thread
apaz-cli marked this conversation as resolved.
Resolved
total_step: int | None = None
step_batch_size: int | None = None # will be use to create stable file
rollout_path: str | None = None
sampling_params: SamplingParamConfig = SamplingParamConfig()


def fake_chat_template(messages):
Expand Down Expand Up @@ -124,7 +143,24 @@ def weights_iterator():
def main(config: Config): # -> list[dict[str, Any]]:
prompts = ["Write me a novel" for _ in range(5)]

llm = LLM(model=name_to_hf_model[config.name_model], tensor_parallel_size=config.tp)
if config.tp == "all":
config.tp = torch.cuda.device_count()

if config.cpu_offload_gb != 0.0 and config.cpu_offload_percentage != 0.0:
raise ValueError("Cannot set both cpu_offload_gb and cpu_offload_percentage")
if config.cpu_offload_percentage != 0.0:
cpu_offload_gb = psutil.virtual_memory().available * config.cpu_offload_percentage
elif config.cpu_offload_gb != 0.0:
cpu_offload_gb = config.cpu_offload_gb
else:
cpu_offload_gb = 0.0
Comment on lines +149 to +156

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can skip this for now as we don't need offloading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we probably will in the future, and it was basically zero effort. The config I wrote isn't offloading.


llm = LLM(
model=name_to_hf_model[config.name_model],
tensor_parallel_size=config.tp,
max_model_len=config.max_seq_len,
cpu_offload_gb=cpu_offload_gb,
)
logger = get_logger("INFERENCE")

sampling_params = SamplingParams(temperature=0.7, top_p=0.95, max_tokens=100, presence_penalty=0.1, frequency_penalty=0.1)
Expand Down
22 changes: 16 additions & 6 deletions src/zeroband/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,36 @@
AutoTokenizer,
LlamaConfig,
LlamaForCausalLM,
Qwen2Config,
Qwen2ForCausalLM,
)

ModelName: TypeAlias = Literal["debugmodel", "150M", "1B"]
ModelName: TypeAlias = Literal["debugmodel", "150M", "1B", "Qwen32B"]

name_to_hf_model = {
"debugmodel": "PrimeIntellect/llama-2m-fresh",
"150M": "PrimeIntellect/llama-150m-fresh",
"1B": "PrimeIntellect/llama-1b-fresh",
"Qwen32B": "Qwen/Qwen2.5-32B",
}

name_to_hf_tokenizer = {
"debugmodel": "mistralai/Mistral-7B-v0.1",
"150M": "mistralai/Mistral-7B-v0.1",
"1B": "mistralai/Mistral-7B-v0.1",
"Qwen32B": "Qwen/Qwen2.5-32B",
Comment thread
apaz-cli marked this conversation as resolved.
Resolved
}

name_to_class = {
"debugmodel": (LlamaConfig, LlamaForCausalLM),
"150M": (LlamaConfig, LlamaForCausalLM),
"1B": (LlamaConfig, LlamaForCausalLM),
"Qwen32B": (Qwen2Config, Qwen2ForCausalLM),
}

def get_model_and_tokenizer(model_name: ModelName) -> tuple[torch.nn.Module, AutoTokenizer, int]:
def get_model_and_tokenizer(model_name: ModelName) -> tuple[torch.nn.Module, AutoTokenizer]:
config_class, model_class = name_to_class[model_name]
tokenizer = AutoTokenizer.from_pretrained(name_to_hf_tokenizer[model_name])
config_model = LlamaConfig.from_pretrained(name_to_hf_model[model_name], attn_implementation="flex_attention")
model = LlamaForCausalLM.from_pretrained(pretrained_model_name_or_path=name_to_hf_model[model_name], config=config_model)
config_model = config_class.from_pretrained(name_to_hf_model[model_name], attn_implementation="flex_attention")
model = model_class.from_pretrained(pretrained_model_name_or_path=name_to_hf_model[model_name], config=config_model)
tokenizer.pad_token_id = tokenizer.eos_token_id
return model, tokenizer
return model, tokenizer # type: ignore
Comment thread
apaz-cli marked this conversation as resolved.
Resolved