Views
No views yet
1# ----------------------------------------------------------------------
2# merge_weighted_average.yaml
3# Weighted‑average merge of two 2‑B LLMs
4# ----------------------------------------------------------------------
5# Merge method
6# ----------------------------------------------------------------------
7merge_method: linear
8
9# ----------------------------------------------------------------------
10# Base models + per‑model weights
11# ----------------------------------------------------------------------
12# The list can be extended (just add another entry with its weight).
13# The `normalize: true` flag below will automatically scale the
14# weights so that their sum equals 1.0.
15models:
16 - model: powermove72/granite-3.3-2b-Hermes3dataset
17 parameters:
18 weight: 0.6
19 - model: ibm-granite/granite-3.3-2b-instruct
20 parameters:
21 weight: 0.4
22
23# ----------------------------------------------------------------------
24# Tokenizer
25# ----------------------------------------------------------------------
26# All source models share the same tokenizer (Llama‑2’s tokenizer).
27# If you later decide to use a different tokenizer, just change this line.
28tokenizer_source: powermove72/granite-3.3-2b-Hermes3dataset
29
30# ----------------------------------------------------------------------
31# Precision & device handling
32# ----------------------------------------------------------------------
33# bfloat16 is the preferred dtype on modern GPUs (A100, H100, RTX 4090, etc.)
34# because it offers the dynamic range of float16 without the overflow risk.
35# If the current runtime cannot run bfloat16, the merger will fall back
36# to float16 automatically.
37dtype: bfloat16
38
39# ----------------------------------------------------------------------
40# Merge‑specific parameters
41# ----------------------------------------------------------------------
42parameters:
43 # Normalise the per‑model weights so the sum = 1.0 (keeps the
44 # merged tensor magnitude comparable to the originals).
45 normalize: true
46
47 # Load the checkpoints with the “low‑cpu‑mem” strategy – only the
48 # tensors needed for the current layer are streamed onto GPU.
49 low_cpu_mem_usage: true
50
51 # Optional: add a small amount of Gaussian jitter to break exact
52 # symmetry when two models have identical weights in a layer.
53 # jitter_std: 0.001 # ← uncomment if you ever need it
54
55# ----------------------------------------------------------------------
56# Reproducibility & deterministic execution
57# ----------------------------------------------------------------------
58seed: 2025 # any integer you like
59deterministic: true # forces torch‑cudnn deterministic mode
601!pip install -qU transformers accelerate
2
3from transformers import AutoTokenizer
4import transformers
5import torch
6
7model = "powermove72/Granite-3.3-2B-Avg"
8messages = [{"role": "user", "content": "What is a large language model?"}]
9
10tokenizer = AutoTokenizer.from_pretrained(model)
11prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
12pipeline = transformers.pipeline(
13 "text-generation",
14 model=model,
15 torch_dtype=torch.float16,
16 device_map="auto",
17)
18
19outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
20print(outputs[0]["generated_text"])