omarkamali commited on
Commit
594a309
·
verified ·
1 Parent(s): 4d4c193

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: residuals
3
+ base_model: google/gemma-3-4b-pt
4
+ base_model_relation: adapter
5
+ instruct_model: google/gemma-3-4b-it
6
+ pipeline_tag: text-generation
7
+ tags:
8
+ - residuals
9
+ - delta
10
+ - task-arithmetic
11
+ - finetune
12
+ ---
13
+
14
+
15
+ # Instruction Residuals
16
+
17
+ This repository contains instruction residuals (delta weights) computed as the parameter-wise difference between `google/gemma-3-4b-it` and `google/gemma-3-4b-pt`.
18
+
19
+ Apply these residuals to the base model to reconstruct the instruction-tuned weights without retraining.
20
+
21
+
22
+ ## Usage
23
+
24
+ ```python
25
+ from transformers import AutoModelForCausalLM, AutoTokenizer
26
+ from residuals import Residuals
27
+
28
+ base = AutoModelForCausalLM.from_pretrained("google/gemma-3-4b-pt")
29
+ tok = AutoTokenizer.from_pretrained("google/gemma-3-4b-pt")
30
+
31
+ res = Residuals.from_pretrained("residuals/gemma-3-4b")
32
+ res.apply(base, base_tokenizer=tok)
33
+ ```
34
+
35
+
36
+ ## Provenance
37
+ - **Created at**: 2025-10-25T18:45:30.975057+00:00
38
+ - **DType**: float32
39
+ - **Parameters**: 884
40
+ - **Shapes hash**: 0aad859058a45de47ddd36c2e67a97e30be0a99b7da51dcfb62e4797e27328d8
41
+ - **Names hash**: 22ce2085d7e0c22fd49d378204b2df3f6a4013610f03e7102733ed62b50259c3
42
+ - **Base model**: `google/gemma-3-4b-pt`
43
+ - **Instruction model**: `google/gemma-3-4b-it`
44
+
45
+ ## Files
46
+ - **model.safetensors**: Serialized residual tensors (safetensors format).
47
+ - (optional) **model.safetensors.index.json** + shard files `model-00001-of-000N.safetensors`, ... for multi-part weights.
48
+ - **config.json**: Residuals metadata and provenance.
49
+ - **tokenizer files**: Saved tokenizer for compatibility.
50
+
51
+ ## About this format
52
+ These are additive residuals (task vectors). Applying them to the base model's parameters reconstructs the instruction-tuned model.
53
+
54
+ ## Tools
55
+ Generated with the `residuals` Python package. Install via: `pip install residuals`.
56
+ - PyPI: https://pypi.org/project/residuals/
57
+ - Source: https://github.com/omarish/residuals
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "<image_soft_token>": 262144
3
+ }
chat_template.jinja ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{ bos_token }}
2
+ {%- if messages[0]['role'] == 'system' -%}
3
+ {%- if messages[0]['content'] is string -%}
4
+ {%- set first_user_prefix = messages[0]['content'] + '
5
+
6
+ ' -%}
7
+ {%- else -%}
8
+ {%- set first_user_prefix = messages[0]['content'][0]['text'] + '
9
+
10
+ ' -%}
11
+ {%- endif -%}
12
+ {%- set loop_messages = messages[1:] -%}
13
+ {%- else -%}
14
+ {%- set first_user_prefix = "" -%}
15
+ {%- set loop_messages = messages -%}
16
+ {%- endif -%}
17
+ {%- for message in loop_messages -%}
18
+ {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
19
+ {{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
20
+ {%- endif -%}
21
+ {%- if (message['role'] == 'assistant') -%}
22
+ {%- set role = "model" -%}
23
+ {%- else -%}
24
+ {%- set role = message['role'] -%}
25
+ {%- endif -%}
26
+ {{ '<start_of_turn>' + role + '
27
+ ' + (first_user_prefix if loop.first else "") }}
28
+ {%- if message['content'] is string -%}
29
+ {{ message['content'] | trim }}
30
+ {%- elif message['content'] is iterable -%}
31
+ {%- for item in message['content'] -%}
32
+ {%- if item['type'] == 'image' -%}
33
+ {{ '<start_of_image>' }}
34
+ {%- elif item['type'] == 'text' -%}
35
+ {{ item['text'] | trim }}
36
+ {%- endif -%}
37
+ {%- endfor -%}
38
+ {%- else -%}
39
+ {{ raise_exception("Invalid content type") }}
40
+ {%- endif -%}
41
+ {{ '<end_of_turn>
42
+ ' }}
43
+ {%- endfor -%}
44
+ {%- if add_generation_prompt -%}
45
+ {{'<start_of_turn>model
46
+ '}}
47
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "residuals_version": "1.0",
3
+ "format": "pytorch",
4
+ "dtype": "float32",
5
+ "param_count": 884,
6
+ "shapes_hash": "0aad859058a45de47ddd36c2e67a97e30be0a99b7da51dcfb62e4797e27328d8",
7
+ "parameter_names_hash": "22ce2085d7e0c22fd49d378204b2df3f6a4013610f03e7102733ed62b50259c3",
8
+ "tokenizer_name": "google/gemma-3-4b-it",
9
+ "created_at": "2025-10-25T18:45:30.975057+00:00",
10
+ "library": {
11
+ "package": "residuals"
12
+ },
13
+ "base_model_name": "google/gemma-3-4b-pt",
14
+ "instruct_model_name": "google/gemma-3-4b-it",
15
+ "pipeline_tag": "text-generation",
16
+ "license": null,
17
+ "language": null,
18
+ "tags": [
19
+ "residuals",
20
+ "delta",
21
+ "task-arithmetic",
22
+ "finetune"
23
+ ],
24
+ "base_model_relation": "adapter"
25
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:303ba64a04f552541c699e1583772fced1b6802a7ee3c361f389c27809ffba3a
3
+ size 19885450136
special_tokens_map.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "boi_token": "<start_of_image>",
3
+ "bos_token": {
4
+ "content": "<bos>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false
9
+ },
10
+ "eoi_token": "<end_of_image>",
11
+ "eos_token": {
12
+ "content": "<eos>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false
17
+ },
18
+ "image_token": "<image_soft_token>",
19
+ "pad_token": {
20
+ "content": "<pad>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false
25
+ },
26
+ "unk_token": {
27
+ "content": "<unk>",
28
+ "lstrip": false,
29
+ "normalized": false,
30
+ "rstrip": false,
31
+ "single_word": false
32
+ }
33
+ }
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1299c11d7cf632ef3b4e11937501358ada021bbdf7c47638d13c0ee982f2e79c
3
+ size 4689074
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff