lschiweck commited on
Commit
8e49cd2
·
1 Parent(s): 0107764

Add SetCon-LM: language model on the frozen encoder (three seeds) (#1)

Browse files

- Add SetCon-LM: language model on the frozen encoder (three seeds) (57ab43914f576cc068c19761ec256b81eeead8b7)

CHECKSUMS.txt CHANGED
@@ -1,14 +1,40 @@
1
  34448b82c17d60fec9b65b1f093c115ddbaadc04beb1b0140b6bfed2e012a930 .gitattributes
2
  41003d4a74749c0220e33dd415042164b5a1093ed401f36277234f772d22d3d0 LICENSE
3
- 752be7acb6522c76700ebcbbdeb437293e536312b68c5db6c6160af0555b7b37 README.md
4
  b69d37fcc55e362a0dbb728aee069047f2e847980cdda3f24c6e195d2c304174 config.json
5
  dc956f3f7d08803de98fb2a773fe634cce9adb076a5aeaac151e5340073c7be0 configuration_setcon.py
 
6
  5ea1c68276212f311d3f233f91947c3c5df9c78deaba83f86fa18f9c0cfb2742 error_bank.json
 
7
  5b1fc8961fa2b1c120c7442e716c92cc45776aef72094f54239e51fb56f3c2e4 examples/reproduce_table1.py
8
  48a2d7194375bf875150b52695fe7c48ade478d8414589718b82fd77567a2644 examples/zero_shot.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  50dc00dfa5bf377833329f3933929c9cc0eadc2bf66ba58fa9d45696d5c9bc9b model.safetensors
10
  ba588c4e0cde8313bcc156e0517f078fc8648c8fdf87bd3d4d79c53667e73d3f modeling_setcon.py
 
11
  2fae7f430b9a7f2295da9ee937304e743d80811a91cbed17f7d347e141fba18a processing_setcon.py
 
12
  2f764642175065967a76c51e1cb237acec396e4fc421d7b298fb338ab02f9fc5 requirements.txt
13
  b51738977aa0ada57da8794844d9e18f7e7ba093603e88a62f1eae4b96d0d894 seed2/config.json
14
  ab0386be5d2ef7cf02cda9f2c18a0f6a29fdc7415049c9226553c619ad82d060 seed2/model.safetensors
 
1
  34448b82c17d60fec9b65b1f093c115ddbaadc04beb1b0140b6bfed2e012a930 .gitattributes
2
  41003d4a74749c0220e33dd415042164b5a1093ed401f36277234f772d22d3d0 LICENSE
3
+ d0f7c8b11508ed4e81b3ba85b28a79d4684e112b7a73578940da30446092299e README.md
4
  b69d37fcc55e362a0dbb728aee069047f2e847980cdda3f24c6e195d2c304174 config.json
5
  dc956f3f7d08803de98fb2a773fe634cce9adb076a5aeaac151e5340073c7be0 configuration_setcon.py
6
+ c33e93f88f9461177242acf567946fae6eb1d2cd6da4cc5cb31f6ca8c7725cf8 configuration_setcon_lm.py
7
  5ea1c68276212f311d3f233f91947c3c5df9c78deaba83f86fa18f9c0cfb2742 error_bank.json
8
+ d0d8cc8ff9c872089bd9e95e294a076f4ec5f7b46e46be2505f4a97a99361d82 examples/ask_lm.py
9
  5b1fc8961fa2b1c120c7442e716c92cc45776aef72094f54239e51fb56f3c2e4 examples/reproduce_table1.py
10
  48a2d7194375bf875150b52695fe7c48ade478d8414589718b82fd77567a2644 examples/zero_shot.py
11
+ bbedc3fda3305820b977265f01b8619d87570a6739de3a5582c3464840f1e57a lm/LICENSE-QWEN
12
+ 273d8e0e683b885071fb17e08d71e5f2a5ddfb5309756181681de4f5a1822d80 lm/chat_template.jinja
13
+ 953559874f4fbc921f3d66da39d5f924c18e40ede51aece710671a2a8b3156bf lm/config.json
14
+ a9d356d7bdf1ef4949e3e748e95b8e10ad9d4e2e838eddc38a0a7b6b94d1db8d lm/merges.txt
15
+ aa3e57404719659df08bf3f6cecb165169ef6265dceba218f825cd740a340dcb lm/model.safetensors
16
+ 273d8e0e683b885071fb17e08d71e5f2a5ddfb5309756181681de4f5a1822d80 lm/seed2/chat_template.jinja
17
+ 4e77ea12a83f183cd85ba4eded8fc5405542bca9a62508806687628be483d8b0 lm/seed2/config.json
18
+ a9d356d7bdf1ef4949e3e748e95b8e10ad9d4e2e838eddc38a0a7b6b94d1db8d lm/seed2/merges.txt
19
+ 37483efb76a63c9697ab5497d889bed824125481c0fd769c523d4f4d2d93ce43 lm/seed2/model.safetensors
20
+ 5f9e4d4901a92b997e463c1f46055088b6cca5ca61a6522d1b9f64c4bb81cb42 lm/seed2/tokenizer.json
21
+ 49e2b6e395f959f077f1e992b338919c0d4a9732fc6e613995e06557f843500c lm/seed2/tokenizer_config.json
22
+ ce99b4cb2983d118806ce0a8b777a35b093e2000a503ebde25853284c9dfa003 lm/seed2/vocab.json
23
+ 273d8e0e683b885071fb17e08d71e5f2a5ddfb5309756181681de4f5a1822d80 lm/seed3/chat_template.jinja
24
+ 91422fd187e6115904fdf9cf92e019c024120f66efb3cb95a8c9e84d8fc16fef lm/seed3/config.json
25
+ a9d356d7bdf1ef4949e3e748e95b8e10ad9d4e2e838eddc38a0a7b6b94d1db8d lm/seed3/merges.txt
26
+ eb89bcfbd4518b080ec5d440b58f1c87a5dfdbba1cd3e866fb2d1e0594aadc63 lm/seed3/model.safetensors
27
+ 5f9e4d4901a92b997e463c1f46055088b6cca5ca61a6522d1b9f64c4bb81cb42 lm/seed3/tokenizer.json
28
+ 49e2b6e395f959f077f1e992b338919c0d4a9732fc6e613995e06557f843500c lm/seed3/tokenizer_config.json
29
+ ce99b4cb2983d118806ce0a8b777a35b093e2000a503ebde25853284c9dfa003 lm/seed3/vocab.json
30
+ 5f9e4d4901a92b997e463c1f46055088b6cca5ca61a6522d1b9f64c4bb81cb42 lm/tokenizer.json
31
+ 49e2b6e395f959f077f1e992b338919c0d4a9732fc6e613995e06557f843500c lm/tokenizer_config.json
32
+ ce99b4cb2983d118806ce0a8b777a35b093e2000a503ebde25853284c9dfa003 lm/vocab.json
33
  50dc00dfa5bf377833329f3933929c9cc0eadc2bf66ba58fa9d45696d5c9bc9b model.safetensors
34
  ba588c4e0cde8313bcc156e0517f078fc8648c8fdf87bd3d4d79c53667e73d3f modeling_setcon.py
35
+ 2dd1b3b454faa5ca204b8ce283cb9ba54d21bb4f139404319d16acdc75dd3d62 modeling_setcon_lm.py
36
  2fae7f430b9a7f2295da9ee937304e743d80811a91cbed17f7d347e141fba18a processing_setcon.py
37
+ b78174f461b36a31b959360b94351900c6e1f3bb96d260e2fd41ff98be91b694 requirements-lm.txt
38
  2f764642175065967a76c51e1cb237acec396e4fc421d7b298fb338ab02f9fc5 requirements.txt
39
  b51738977aa0ada57da8794844d9e18f7e7ba093603e88a62f1eae4b96d0d894 seed2/config.json
40
  ab0386be5d2ef7cf02cda9f2c18a0f6a29fdc7415049c9226553c619ad82d060 seed2/model.safetensors
README.md CHANGED
@@ -35,7 +35,8 @@ mounting, SetCon replaces full invariance with selective invariance. A calibrato
35
  each device on its known body site from a few unlabeled windows, and the encoder receives every window rotated so
36
  that gravity points up together with gravity in the segment frame. Both networks were trained only on IMU simulated
37
  from the Nymeria motion capture. On 13 real datasets SetCon reaches 56.6 % mean zero-shot accuracy with class names
38
- and 65.3 % with anchors, against 41.8 % and 46.7 % for AnyMo.
 
39
 
40
  The model and its code are released for non-commercial research.
41
 
@@ -45,14 +46,21 @@ The model and its code are released for non-commercial research.
45
  SetCon/
46
  ├── config.json, model.safetensors seed 1 (default): encoder + calibrator
47
  ├── seed2/, seed3/ the two other stage-2 seeds (same stage-1 model and calibrator)
 
 
 
48
  ├── configuration_setcon.py remote code: configuration
49
  ├── modeling_setcon.py remote code: encoder, calibrator, inference helpers
50
  ├── processing_setcon.py body sites, gravity canonicalization, calibrator input, 6-of-12 selection
 
 
51
  ├── setcon/ evaluation package that recomputes the paper's numbers
52
  ├── examples/zero_shot.py load, embed one window, classify against class names
 
53
  ├── examples/reproduce_table1.py Tab. 1 and the abstract (with --all: Tab. 2, Tab. 3, Sec. 4.3-4.4)
54
  ├── error_bank.json which calibrator the encoders were trained with, and its errors
55
  ├── requirements.txt, CHECKSUMS.txt
 
56
  └── LICENSE CC BY-NC 4.0, for the weights and the code
57
  ```
58
 
@@ -90,6 +98,57 @@ pred = (z @ class_vectors.T).argmax(1) # class_vectors: unit CLIP ViT-
90
  `model.select_context(windows12, site)` picks six of twelve unlabeled windows by the calibrator's tilt uncertainty,
91
  as in the last row of Tab. 1.
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  ## Reproducing the paper's numbers
94
 
95
  ```bash
@@ -167,9 +226,9 @@ dataset or test participant is used in training. Training code is not part of th
167
 
168
  ## Not included
169
 
170
- - The language model on top of the encoder (paper Sec. 3.6, the last row of Tab. 2 and the language-model numbers of
171
- Sec. 4.4). Its numbers cannot be recomputed from this repository.
172
- - Training code, the simulation and the training data pipeline.
173
  - The baselines (UniMTS, AnyMo) and the test data themselves.
174
 
175
  ## Intended use and limitations
@@ -177,6 +236,7 @@ dataset or test participant is used in training. Training code is not part of th
177
  SetCon is meant for non-commercial research on wearable activity recognition, IMU-language representations and
178
  zero-shot classification. It assumes that the body site of each device is known and that the mounting stays fixed
179
  while the device is worn. Unscripted daily life, in which devices slip and sites are unknown, remains to be tested.
 
180
  Activity recognition reveals what the wearer does, so deployment requires the wearers' informed consent. The model
181
  must not be the sole basis for clinical or other high-stakes decisions.
182
 
@@ -184,6 +244,7 @@ must not be the sole basis for clinical or other high-stakes decisions.
184
 
185
  - Model weights: CC BY-NC 4.0 (`LICENSE`), because they were trained on Nymeria (CC BY-NC 4.0). The body model MHR
186
  used for the simulation is licensed under Apache 2.0.
 
187
  - Code in this repository: CC BY-NC 4.0 (`LICENSE`), like the weights.
188
  - Evaluation data: CC BY-NC 4.0 (separate dataset repository; it contains Nymeria narration sentences).
189
  - Test data: not included; each benchmark keeps its own terms.
 
35
  each device on its known body site from a few unlabeled windows, and the encoder receives every window rotated so
36
  that gravity points up together with gravity in the segment frame. Both networks were trained only on IMU simulated
37
  from the Nymeria motion capture. On 13 real datasets SetCon reaches 56.6 % mean zero-shot accuracy with class names
38
+ and 65.3 % with anchors, against 41.8 % and 46.7 % for AnyMo. A language model on the frozen encoder, SetCon-LM
39
+ (Qwen3.5-0.8B), answers questions about a window in free text.
40
 
41
  The model and its code are released for non-commercial research.
42
 
 
46
  SetCon/
47
  ├── config.json, model.safetensors seed 1 (default): encoder + calibrator
48
  ├── seed2/, seed3/ the two other stage-2 seeds (same stage-1 model and calibrator)
49
+ ├── lm/ language model on encoder seed 1: Qwen3.5-0.8B + projector, tokenizer
50
+ │ ├── seed2/, seed3/ the language models on encoder seeds 2 and 3
51
+ │ └── LICENSE-QWEN Apache 2.0 license of the base model Qwen3.5-0.8B
52
  ├── configuration_setcon.py remote code: configuration
53
  ├── modeling_setcon.py remote code: encoder, calibrator, inference helpers
54
  ├── processing_setcon.py body sites, gravity canonicalization, calibrator input, 6-of-12 selection
55
+ ├── configuration_setcon_lm.py remote code: language model configuration (prompt, site names)
56
+ ├── modeling_setcon_lm.py remote code: language model (projector, prompt, ask / choose / yes_no)
57
  ├── setcon/ evaluation package that recomputes the paper's numbers
58
  ├── examples/zero_shot.py load, embed one window, classify against class names
59
+ ├── examples/ask_lm.py load encoder + language model, ask about one real window
60
  ├── examples/reproduce_table1.py Tab. 1 and the abstract (with --all: Tab. 2, Tab. 3, Sec. 4.3-4.4)
61
  ├── error_bank.json which calibrator the encoders were trained with, and its errors
62
  ├── requirements.txt, CHECKSUMS.txt
63
+ ├── requirements-lm.txt environment of the language model (transformers 5)
64
  └── LICENSE CC BY-NC 4.0, for the weights and the code
65
  ```
66
 
 
98
  `model.select_context(windows12, site)` picks six of twelve unlabeled windows by the calibrator's tilt uncertainty,
99
  as in the last row of Tab. 1.
100
 
101
+ ## Language model
102
+
103
+ SetCon-LM puts Qwen3.5-0.8B on the frozen encoder (paper Sec. 3.6) and answers questions about a window in free
104
+ text, for example what the person is doing or how the activity is performed. A projector maps the encoder's setup
105
+ vector (from the worn-site and gyroscope flags) to one token and its feature of every worn site and 0.2-s patch to one
106
+ token each. These tokens precede a chat prompt that names the worn sites and asks the question. The projector was
107
+ first trained to caption simulated windows with the language model frozen, then together with the language model on
108
+ captions and question-answer pairs that an LLM wrote from the narrations and the measured motion of each window.
109
+
110
+ ```python
111
+ from transformers import AutoModel
112
+
113
+ setcon = AutoModel.from_pretrained("lschiweck/SetCon", trust_remote_code=True).to("cuda").eval()
114
+ lm = AutoModel.from_pretrained("lschiweck/SetCon", subfolder="lm", trust_remote_code=True).to("cuda").eval()
115
+ # x: (N, 200, 22, 9) windows with the setup reference set, as in Usage above
116
+ lm.ask(setcon, x, "What is the person doing?") # one answer per window
117
+ lm.ask(setcon, x, "How is the activity performed in terms of pace?")
118
+ lm.choose(setcon, x, "Which activity is this: A) walking B) sitting?", ["A) walking", "B) sitting"])
119
+ ```
120
+
121
+ `ask` decodes greedily. `choose` picks the candidate answer with the lowest mean token loss, and `yes_no` compares
122
+ "Yes" and "No" as the first answer token; this is how the paper scores its questions with candidate answers.
123
+ `lm/seed2` and `lm/seed3` belong to the encoders `seed2` and `seed3` and refuse any other encoder. Each language model
124
+ holds the fine-tuned Qwen3.5-0.8B (input and output embeddings tied) and the projector in float32, the weights at the
125
+ end of training (3.0 GB per seed). It needs `requirements-lm.txt` (Python >= 3.10, transformers 5); the encoder alone
126
+ runs with `requirements.txt`. `examples/ask_lm.py` asks about a window of UCI-HAR.
127
+
128
+ Numbers of the paper (Sec. 4.4 and Tab. 2), mean over the three seeds, in %:
129
+
130
+ | Question | Paper |
131
+ |---|---:|
132
+ | "What is the person doing?", free answer mapped to a class name by an LLM judge, Mean-13 accuracy with six random context windows (Tab. 2) | 59.2 ± 1.5 |
133
+ | Encoder on the same windows, class names / anchors | 55.9 / 64.7 |
134
+ | Held-out simulated Nymeria windows, five-way questions on execution / order / body region (chance 20) | 71 / 64 / 46 |
135
+ | Same windows, five-way activity question (chance 20) / four-way activity choice (chance 25) | 58 / 82 |
136
+ | Same windows, yes/no questions (chance 50) | 80 |
137
+
138
+ The answers depend on the signal: without the IMU tokens the free answers reach 5.6 % Mean-13 accuracy (on a subset
139
+ of the windows of Tab. 2), and given the IMU tokens of another window they name that window's class in 59 % of cases.
140
+
141
+ These numbers cannot be recomputed from this repository alone. The Mean-13 accuracy needs the LLM judge
142
+ (Qwen3.6-27B), and the held-out questions need simulated windows; neither is released. With the settings below, the
143
+ released language models give the paper run's answers word for word.
144
+
145
+ Fixed settings: encoder and projector under bfloat16 autocast on CUDA, the language model in float32 without
146
+ autocast, batches of 32 windows (left padding), greedy decoding with at most 48 new tokens, stop at `<|im_end|>` or
147
+ `<|endoftext|>`. The Gated DeltaNet layers use the flash-linear-attention kernels with
148
+ `FLA_DISABLE_BACKEND_DISPATCH=1` (set by the remote code unless already set). Reference environment: Python 3.12,
149
+ torch 2.8.0+cu128, transformers 5.14.1, flash-linear-attention 0.5.2, causal-conv1d 1.7.0, triton 3.7.1. Other
150
+ devices, precisions, batch sizes or kernels can change single answers.
151
+
152
  ## Reproducing the paper's numbers
153
 
154
  ```bash
 
226
 
227
  ## Not included
228
 
229
+ - The LLM judge that maps the language model's free answers to class names, and the simulated held-out windows of
230
+ its questions with given answers.
231
+ - Training code (encoder, calibrator and language model), the simulation and the training data pipeline.
232
  - The baselines (UniMTS, AnyMo) and the test data themselves.
233
 
234
  ## Intended use and limitations
 
236
  SetCon is meant for non-commercial research on wearable activity recognition, IMU-language representations and
237
  zero-shot classification. It assumes that the body site of each device is known and that the mounting stays fixed
238
  while the device is worn. Unscripted daily life, in which devices slip and sites are unknown, remains to be tested.
239
+ The language model writes fluent sentences also when they are wrong.
240
  Activity recognition reveals what the wearer does, so deployment requires the wearers' informed consent. The model
241
  must not be the sole basis for clinical or other high-stakes decisions.
242
 
 
244
 
245
  - Model weights: CC BY-NC 4.0 (`LICENSE`), because they were trained on Nymeria (CC BY-NC 4.0). The body model MHR
246
  used for the simulation is licensed under Apache 2.0.
247
+ - Language model weights (`lm/`): CC BY-NC 4.0 as well, fine-tuned from Qwen3.5-0.8B (Apache 2.0, `lm/LICENSE-QWEN`).
248
  - Code in this repository: CC BY-NC 4.0 (`LICENSE`), like the weights.
249
  - Evaluation data: CC BY-NC 4.0 (separate dataset repository; it contains Nymeria narration sentences).
250
  - Test data: not included; each benchmark keeps its own terms.
configuration_setcon_lm.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Configuration of SetCon-LM, the language model on the frozen SetCon encoder (Hugging Face remote code).
2
+
3
+ Needs transformers >= 5 (Qwen3.5). The SetCon encoder itself also loads with transformers 4.57.
4
+ """
5
+ from __future__ import annotations
6
+
7
+ import os
8
+
9
+ # The paper's runs used the Triton kernels of flash-linear-attention for the Gated DeltaNet layers of Qwen3.5 and
10
+ # disabled its backend dispatch. Must be set before `fla` is imported; an explicit user setting wins.
11
+ os.environ.setdefault("FLA_DISABLE_BACKEND_DISPATCH", "1")
12
+
13
+ from transformers import PretrainedConfig # noqa: E402
14
+ from transformers.models.qwen3_5.configuration_qwen3_5 import Qwen3_5TextConfig # noqa: E402
15
+
16
+ # The system prompt of every question during training and in the paper's evaluation.
17
+ SYSTEM_PROMPT = ("Continuous tokens from sparse wearable IMUs are provided before this text. Answer the question about "
18
+ "the observed motion in one or two short sentences.")
19
+ # Names of the 22 body sites in the prompt line "Sensors worn at: ...", in the order of processing_setcon.SITE_NAMES.
20
+ SITE_TEXT = ("pelvis", "left hip", "left knee", "left ankle", "left foot", "right hip", "right knee", "right ankle",
21
+ "right foot", "spine", "upper spine", "chest", "neck", "head", "left collar", "left shoulder",
22
+ "left elbow", "left wrist", "right collar", "right shoulder", "right elbow", "right wrist")
23
+
24
+
25
+ class SetConLMConfig(PretrainedConfig):
26
+ """Qwen3.5-0.8B (text part, `text_config`) plus the projector from SetCon encoder features to LM inputs.
27
+
28
+ encoder_training_seed the SetCon checkpoint this LM was trained on (1 = repository root, 2 / 3 = seed2/, seed3/)
29
+ encoder_hidden_size width of the encoder's setup vector and patch tokens (256)
30
+ num_sites, num_patches the encoder's 22 body sites and 50 patches of 0.2 s
31
+ """
32
+
33
+ model_type = "setcon_lm"
34
+ sub_configs = {"text_config": Qwen3_5TextConfig}
35
+
36
+ def __init__(
37
+ self,
38
+ text_config=None,
39
+ encoder_training_seed: int = 1,
40
+ encoder_hidden_size: int = 256,
41
+ num_sites: int = 22,
42
+ num_patches: int = 50,
43
+ system_prompt: str = SYSTEM_PROMPT,
44
+ site_text: tuple = SITE_TEXT,
45
+ default_question: str = "What is the person doing?",
46
+ max_new_tokens: int = 48,
47
+ batch_size: int = 32,
48
+ stop_tokens: tuple = ("<|im_end|>", "<|endoftext|>"),
49
+ base_model: str = "Qwen/Qwen3.5-0.8B",
50
+ **kwargs,
51
+ ):
52
+ if isinstance(text_config, dict):
53
+ text_config = Qwen3_5TextConfig(**text_config)
54
+ self.text_config = text_config if text_config is not None else Qwen3_5TextConfig()
55
+ self.encoder_training_seed = int(encoder_training_seed)
56
+ self.encoder_hidden_size = int(encoder_hidden_size)
57
+ self.num_sites = int(num_sites)
58
+ self.num_patches = int(num_patches)
59
+ self.system_prompt = str(system_prompt)
60
+ self.site_text = [str(s) for s in site_text]
61
+ self.default_question = str(default_question)
62
+ self.max_new_tokens = int(max_new_tokens)
63
+ self.batch_size = int(batch_size)
64
+ self.stop_tokens = [str(t) for t in stop_tokens]
65
+ self.base_model = str(base_model)
66
+ super().__init__(**kwargs)
examples/ask_lm.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Ask the language model about a real window: a smartphone on the waist (UCI-HAR test split, participant 2).
2
+
3
+ 1. load SetCon (seed 1) and its language model through transformers
4
+ 2. turn the phone's raw windows into model windows and set the setup reference from six unlabeled windows
5
+ 3. ask what the person is doing and how the activity is performed, then let it choose among four activities
6
+
7
+ python examples/ask_lm.py --unimts-dir <folder with UCIHAR/X_test.npy> (see setcon/data.py for the download)
8
+
9
+ Needs the language model's environment (requirements-lm.txt: transformers 5).
10
+ """
11
+ import argparse
12
+ import json
13
+ import sys
14
+ from pathlib import Path
15
+
16
+ import numpy as np
17
+ import torch
18
+
19
+ REPO = Path(__file__).resolve().parents[1]
20
+ sys.path.insert(0, str(REPO))
21
+ from setcon import load_model, processing # noqa: E402
22
+ from transformers import AutoModel # noqa: E402
23
+
24
+ ap = argparse.ArgumentParser()
25
+ ap.add_argument("--unimts-dir", required=True)
26
+ ap.add_argument("--window", type=int, default=150, help="window of participant 2 to ask about (0-301)")
27
+ ap.add_argument("--model", default=None, help="local folder or hub id of the repository (default: this one)")
28
+ a = ap.parse_args()
29
+ device = "cuda" if torch.cuda.is_available() else "cpu"
30
+ repo = a.model or str(REPO)
31
+
32
+ setcon = load_model(seed=1, model=repo, device=device)
33
+ lm = AutoModel.from_pretrained(repo, subfolder="lm", trust_remote_code=True).to(device).eval()
34
+
35
+ # UCI-HAR: 50 Hz, columns 3-5 angular velocity (rad/s), 6-8 total acceleration (g). Participant 2 = windows 0-301.
36
+ d = Path(a.unimts_dir) / "UCIHAR"
37
+ X = np.load(d / "X_test.npy")[:302].astype(np.float64)
38
+ y = np.load(d / "y_test.npy")[:302]
39
+ classes = [" ".join(v) for v in json.loads((d / "UCIHAR.json").read_text())["label_dictionary"].values()]
40
+ windows = processing.prepare_device(acc=X[:, :, 6:9] * 9.80665, gyro=X[:, :, 3:6], fs=50) # (302, 200, 9)
41
+
42
+ # Setup reference from six unlabeled windows of the same device, as for zero-shot classification.
43
+ context = np.random.default_rng(0).choice(len(windows), 6, replace=False)
44
+ ref = setcon.estimate_reference(windows[context], site="c_spine1")
45
+ windows = processing.set_reference(windows, ref["reference"])
46
+ x = processing.place_devices({"c_spine1": windows[a.window:a.window + 1]}) # (1, 200, 22, 9)
47
+ print(f"window {a.window}, true class '{classes[int(y[a.window])]}'")
48
+
49
+ for q in ("What is the person doing?", "How is the activity performed in terms of pace?"):
50
+ print(f"Q: {q}\nA: {lm.ask(setcon, x, q)[0]}")
51
+
52
+ options = ["walking", "sitting", "lying", "walking upstairs"]
53
+ q = "Which activity is this: " + " ".join(f"{'ABCD'[i]}) {o}" for i, o in enumerate(options)) + "?"
54
+ choice = lm.choose(setcon, x, q, [f"{'ABCD'[i]}) {o}" for i, o in enumerate(options)])[0]
55
+ print(f"Q: {q}\nchosen: {options[choice['index']]} (mean token NLL per option: "
56
+ + ", ".join(f"{v:.2f}" for v in choice["nll"]) + ")")
lm/LICENSE-QWEN ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Alibaba Cloud
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
lm/chat_template.jinja ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- set image_count = namespace(value=0) %}
2
+ {%- set video_count = namespace(value=0) %}
3
+ {%- macro render_content(content, do_vision_count, is_system_content=false) %}
4
+ {%- if content is string %}
5
+ {{- content }}
6
+ {%- elif content is iterable and content is not mapping %}
7
+ {%- for item in content %}
8
+ {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
9
+ {%- if is_system_content %}
10
+ {{- raise_exception('System message cannot contain images.') }}
11
+ {%- endif %}
12
+ {%- if do_vision_count %}
13
+ {%- set image_count.value = image_count.value + 1 %}
14
+ {%- endif %}
15
+ {%- if add_vision_id %}
16
+ {{- 'Picture ' ~ image_count.value ~ ': ' }}
17
+ {%- endif %}
18
+ {{- '<|vision_start|><|image_pad|><|vision_end|>' }}
19
+ {%- elif 'video' in item or item.type == 'video' %}
20
+ {%- if is_system_content %}
21
+ {{- raise_exception('System message cannot contain videos.') }}
22
+ {%- endif %}
23
+ {%- if do_vision_count %}
24
+ {%- set video_count.value = video_count.value + 1 %}
25
+ {%- endif %}
26
+ {%- if add_vision_id %}
27
+ {{- 'Video ' ~ video_count.value ~ ': ' }}
28
+ {%- endif %}
29
+ {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
30
+ {%- elif 'text' in item %}
31
+ {{- item.text }}
32
+ {%- else %}
33
+ {{- raise_exception('Unexpected item type in content.') }}
34
+ {%- endif %}
35
+ {%- endfor %}
36
+ {%- elif content is none or content is undefined %}
37
+ {{- '' }}
38
+ {%- else %}
39
+ {{- raise_exception('Unexpected content type.') }}
40
+ {%- endif %}
41
+ {%- endmacro %}
42
+ {%- if not messages %}
43
+ {{- raise_exception('No messages provided.') }}
44
+ {%- endif %}
45
+ {%- if tools and tools is iterable and tools is not mapping %}
46
+ {{- '<|im_start|>system\n' }}
47
+ {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
48
+ {%- for tool in tools %}
49
+ {{- "\n" }}
50
+ {{- tool | tojson }}
51
+ {%- endfor %}
52
+ {{- "\n</tools>" }}
53
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
54
+ {%- if messages[0].role == 'system' %}
55
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
56
+ {%- if content %}
57
+ {{- '\n\n' + content }}
58
+ {%- endif %}
59
+ {%- endif %}
60
+ {{- '<|im_end|>\n' }}
61
+ {%- else %}
62
+ {%- if messages[0].role == 'system' %}
63
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
64
+ {{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
65
+ {%- endif %}
66
+ {%- endif %}
67
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
68
+ {%- for message in messages[::-1] %}
69
+ {%- set index = (messages|length - 1) - loop.index0 %}
70
+ {%- if ns.multi_step_tool and message.role == "user" %}
71
+ {%- set content = render_content(message.content, false)|trim %}
72
+ {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
73
+ {%- set ns.multi_step_tool = false %}
74
+ {%- set ns.last_query_index = index %}
75
+ {%- endif %}
76
+ {%- endif %}
77
+ {%- endfor %}
78
+ {%- if ns.multi_step_tool %}
79
+ {{- raise_exception('No user query found in messages.') }}
80
+ {%- endif %}
81
+ {%- for message in messages %}
82
+ {%- set content = render_content(message.content, true)|trim %}
83
+ {%- if message.role == "system" %}
84
+ {%- if not loop.first %}
85
+ {{- raise_exception('System message must be at the beginning.') }}
86
+ {%- endif %}
87
+ {%- elif message.role == "user" %}
88
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
89
+ {%- elif message.role == "assistant" %}
90
+ {%- set reasoning_content = '' %}
91
+ {%- if message.reasoning_content is string %}
92
+ {%- set reasoning_content = message.reasoning_content %}
93
+ {%- else %}
94
+ {%- if '</think>' in content %}
95
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
96
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
97
+ {%- endif %}
98
+ {%- endif %}
99
+ {%- set reasoning_content = reasoning_content|trim %}
100
+ {%- if loop.index0 > ns.last_query_index %}
101
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
102
+ {%- else %}
103
+ {{- '<|im_start|>' + message.role + '\n' + content }}
104
+ {%- endif %}
105
+ {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
106
+ {%- for tool_call in message.tool_calls %}
107
+ {%- if tool_call.function is defined %}
108
+ {%- set tool_call = tool_call.function %}
109
+ {%- endif %}
110
+ {%- if loop.first %}
111
+ {%- if content|trim %}
112
+ {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
113
+ {%- else %}
114
+ {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
115
+ {%- endif %}
116
+ {%- else %}
117
+ {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
118
+ {%- endif %}
119
+ {%- if tool_call.arguments is defined %}
120
+ {%- for args_name, args_value in tool_call.arguments|items %}
121
+ {{- '<parameter=' + args_name + '>\n' }}
122
+ {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
123
+ {{- args_value }}
124
+ {{- '\n</parameter>\n' }}
125
+ {%- endfor %}
126
+ {%- endif %}
127
+ {{- '</function>\n</tool_call>' }}
128
+ {%- endfor %}
129
+ {%- endif %}
130
+ {{- '<|im_end|>\n' }}
131
+ {%- elif message.role == "tool" %}
132
+ {%- if loop.previtem and loop.previtem.role != "tool" %}
133
+ {{- '<|im_start|>user' }}
134
+ {%- endif %}
135
+ {{- '\n<tool_response>\n' }}
136
+ {{- content }}
137
+ {{- '\n</tool_response>' }}
138
+ {%- if not loop.last and loop.nextitem.role != "tool" %}
139
+ {{- '<|im_end|>\n' }}
140
+ {%- elif loop.last %}
141
+ {{- '<|im_end|>\n' }}
142
+ {%- endif %}
143
+ {%- else %}
144
+ {{- raise_exception('Unexpected message role.') }}
145
+ {%- endif %}
146
+ {%- endfor %}
147
+ {%- if add_generation_prompt %}
148
+ {{- '<|im_start|>assistant\n' }}
149
+ {%- if enable_thinking is defined and enable_thinking is true %}
150
+ {{- '<think>\n' }}
151
+ {%- else %}
152
+ {{- '<think>\n\n</think>\n\n' }}
153
+ {%- endif %}
154
+ {%- endif %}
lm/config.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "SetConLM"
4
+ ],
5
+ "auto_map": {
6
+ "AutoConfig": "configuration_setcon_lm.SetConLMConfig",
7
+ "AutoModel": "modeling_setcon_lm.SetConLM"
8
+ },
9
+ "base_model": "Qwen/Qwen3.5-0.8B",
10
+ "batch_size": 32,
11
+ "default_question": "What is the person doing?",
12
+ "encoder_hidden_size": 256,
13
+ "encoder_training_seed": 1,
14
+ "max_new_tokens": 48,
15
+ "model_type": "setcon_lm",
16
+ "num_patches": 50,
17
+ "num_sites": 22,
18
+ "site_text": [
19
+ "pelvis",
20
+ "left hip",
21
+ "left knee",
22
+ "left ankle",
23
+ "left foot",
24
+ "right hip",
25
+ "right knee",
26
+ "right ankle",
27
+ "right foot",
28
+ "spine",
29
+ "upper spine",
30
+ "chest",
31
+ "neck",
32
+ "head",
33
+ "left collar",
34
+ "left shoulder",
35
+ "left elbow",
36
+ "left wrist",
37
+ "right collar",
38
+ "right shoulder",
39
+ "right elbow",
40
+ "right wrist"
41
+ ],
42
+ "stop_tokens": [
43
+ "<|im_end|>",
44
+ "<|endoftext|>"
45
+ ],
46
+ "system_prompt": "Continuous tokens from sparse wearable IMUs are provided before this text. Answer the question about the observed motion in one or two short sentences.",
47
+ "text_config": {
48
+ "architectures": [
49
+ "Qwen3_5ForCausalLM"
50
+ ],
51
+ "attention_bias": false,
52
+ "attention_dropout": 0.0,
53
+ "attn_output_gate": true,
54
+ "bos_token_id": null,
55
+ "dtype": "float32",
56
+ "eos_token_id": 248044,
57
+ "full_attention_interval": 4,
58
+ "head_dim": 256,
59
+ "hidden_act": "silu",
60
+ "hidden_size": 1024,
61
+ "initializer_range": 0.02,
62
+ "intermediate_size": 3584,
63
+ "layer_types": [
64
+ "linear_attention",
65
+ "linear_attention",
66
+ "linear_attention",
67
+ "full_attention",
68
+ "linear_attention",
69
+ "linear_attention",
70
+ "linear_attention",
71
+ "full_attention",
72
+ "linear_attention",
73
+ "linear_attention",
74
+ "linear_attention",
75
+ "full_attention",
76
+ "linear_attention",
77
+ "linear_attention",
78
+ "linear_attention",
79
+ "full_attention",
80
+ "linear_attention",
81
+ "linear_attention",
82
+ "linear_attention",
83
+ "full_attention",
84
+ "linear_attention",
85
+ "linear_attention",
86
+ "linear_attention",
87
+ "full_attention"
88
+ ],
89
+ "linear_conv_kernel_dim": 4,
90
+ "linear_key_head_dim": 128,
91
+ "linear_num_key_heads": 16,
92
+ "linear_num_value_heads": 16,
93
+ "linear_value_head_dim": 128,
94
+ "mamba_ssm_dtype": "float32",
95
+ "max_position_embeddings": 262144,
96
+ "mlp_only_layers": [],
97
+ "model_type": "qwen3_5_text",
98
+ "mtp_num_hidden_layers": 1,
99
+ "mtp_use_dedicated_embeddings": false,
100
+ "num_attention_heads": 8,
101
+ "num_hidden_layers": 24,
102
+ "num_key_value_heads": 2,
103
+ "pad_token_id": null,
104
+ "partial_rotary_factor": 0.25,
105
+ "rms_norm_eps": 1e-06,
106
+ "rope_parameters": {
107
+ "mrope_interleaved": true,
108
+ "mrope_section": [
109
+ 11,
110
+ 11,
111
+ 10
112
+ ],
113
+ "partial_rotary_factor": 0.25,
114
+ "rope_theta": 10000000,
115
+ "rope_type": "default"
116
+ },
117
+ "tie_word_embeddings": true,
118
+ "use_cache": true,
119
+ "vocab_size": 248320
120
+ },
121
+ "transformers_version": "5.14.1"
122
+ }
lm/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
lm/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aa3e57404719659df08bf3f6cecb165169ef6265dceba218f825cd740a340dcb
3
+ size 3020424668
lm/seed2/chat_template.jinja ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- set image_count = namespace(value=0) %}
2
+ {%- set video_count = namespace(value=0) %}
3
+ {%- macro render_content(content, do_vision_count, is_system_content=false) %}
4
+ {%- if content is string %}
5
+ {{- content }}
6
+ {%- elif content is iterable and content is not mapping %}
7
+ {%- for item in content %}
8
+ {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
9
+ {%- if is_system_content %}
10
+ {{- raise_exception('System message cannot contain images.') }}
11
+ {%- endif %}
12
+ {%- if do_vision_count %}
13
+ {%- set image_count.value = image_count.value + 1 %}
14
+ {%- endif %}
15
+ {%- if add_vision_id %}
16
+ {{- 'Picture ' ~ image_count.value ~ ': ' }}
17
+ {%- endif %}
18
+ {{- '<|vision_start|><|image_pad|><|vision_end|>' }}
19
+ {%- elif 'video' in item or item.type == 'video' %}
20
+ {%- if is_system_content %}
21
+ {{- raise_exception('System message cannot contain videos.') }}
22
+ {%- endif %}
23
+ {%- if do_vision_count %}
24
+ {%- set video_count.value = video_count.value + 1 %}
25
+ {%- endif %}
26
+ {%- if add_vision_id %}
27
+ {{- 'Video ' ~ video_count.value ~ ': ' }}
28
+ {%- endif %}
29
+ {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
30
+ {%- elif 'text' in item %}
31
+ {{- item.text }}
32
+ {%- else %}
33
+ {{- raise_exception('Unexpected item type in content.') }}
34
+ {%- endif %}
35
+ {%- endfor %}
36
+ {%- elif content is none or content is undefined %}
37
+ {{- '' }}
38
+ {%- else %}
39
+ {{- raise_exception('Unexpected content type.') }}
40
+ {%- endif %}
41
+ {%- endmacro %}
42
+ {%- if not messages %}
43
+ {{- raise_exception('No messages provided.') }}
44
+ {%- endif %}
45
+ {%- if tools and tools is iterable and tools is not mapping %}
46
+ {{- '<|im_start|>system\n' }}
47
+ {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
48
+ {%- for tool in tools %}
49
+ {{- "\n" }}
50
+ {{- tool | tojson }}
51
+ {%- endfor %}
52
+ {{- "\n</tools>" }}
53
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
54
+ {%- if messages[0].role == 'system' %}
55
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
56
+ {%- if content %}
57
+ {{- '\n\n' + content }}
58
+ {%- endif %}
59
+ {%- endif %}
60
+ {{- '<|im_end|>\n' }}
61
+ {%- else %}
62
+ {%- if messages[0].role == 'system' %}
63
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
64
+ {{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
65
+ {%- endif %}
66
+ {%- endif %}
67
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
68
+ {%- for message in messages[::-1] %}
69
+ {%- set index = (messages|length - 1) - loop.index0 %}
70
+ {%- if ns.multi_step_tool and message.role == "user" %}
71
+ {%- set content = render_content(message.content, false)|trim %}
72
+ {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
73
+ {%- set ns.multi_step_tool = false %}
74
+ {%- set ns.last_query_index = index %}
75
+ {%- endif %}
76
+ {%- endif %}
77
+ {%- endfor %}
78
+ {%- if ns.multi_step_tool %}
79
+ {{- raise_exception('No user query found in messages.') }}
80
+ {%- endif %}
81
+ {%- for message in messages %}
82
+ {%- set content = render_content(message.content, true)|trim %}
83
+ {%- if message.role == "system" %}
84
+ {%- if not loop.first %}
85
+ {{- raise_exception('System message must be at the beginning.') }}
86
+ {%- endif %}
87
+ {%- elif message.role == "user" %}
88
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
89
+ {%- elif message.role == "assistant" %}
90
+ {%- set reasoning_content = '' %}
91
+ {%- if message.reasoning_content is string %}
92
+ {%- set reasoning_content = message.reasoning_content %}
93
+ {%- else %}
94
+ {%- if '</think>' in content %}
95
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
96
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
97
+ {%- endif %}
98
+ {%- endif %}
99
+ {%- set reasoning_content = reasoning_content|trim %}
100
+ {%- if loop.index0 > ns.last_query_index %}
101
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
102
+ {%- else %}
103
+ {{- '<|im_start|>' + message.role + '\n' + content }}
104
+ {%- endif %}
105
+ {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
106
+ {%- for tool_call in message.tool_calls %}
107
+ {%- if tool_call.function is defined %}
108
+ {%- set tool_call = tool_call.function %}
109
+ {%- endif %}
110
+ {%- if loop.first %}
111
+ {%- if content|trim %}
112
+ {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
113
+ {%- else %}
114
+ {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
115
+ {%- endif %}
116
+ {%- else %}
117
+ {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
118
+ {%- endif %}
119
+ {%- if tool_call.arguments is defined %}
120
+ {%- for args_name, args_value in tool_call.arguments|items %}
121
+ {{- '<parameter=' + args_name + '>\n' }}
122
+ {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
123
+ {{- args_value }}
124
+ {{- '\n</parameter>\n' }}
125
+ {%- endfor %}
126
+ {%- endif %}
127
+ {{- '</function>\n</tool_call>' }}
128
+ {%- endfor %}
129
+ {%- endif %}
130
+ {{- '<|im_end|>\n' }}
131
+ {%- elif message.role == "tool" %}
132
+ {%- if loop.previtem and loop.previtem.role != "tool" %}
133
+ {{- '<|im_start|>user' }}
134
+ {%- endif %}
135
+ {{- '\n<tool_response>\n' }}
136
+ {{- content }}
137
+ {{- '\n</tool_response>' }}
138
+ {%- if not loop.last and loop.nextitem.role != "tool" %}
139
+ {{- '<|im_end|>\n' }}
140
+ {%- elif loop.last %}
141
+ {{- '<|im_end|>\n' }}
142
+ {%- endif %}
143
+ {%- else %}
144
+ {{- raise_exception('Unexpected message role.') }}
145
+ {%- endif %}
146
+ {%- endfor %}
147
+ {%- if add_generation_prompt %}
148
+ {{- '<|im_start|>assistant\n' }}
149
+ {%- if enable_thinking is defined and enable_thinking is true %}
150
+ {{- '<think>\n' }}
151
+ {%- else %}
152
+ {{- '<think>\n\n</think>\n\n' }}
153
+ {%- endif %}
154
+ {%- endif %}
lm/seed2/config.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "SetConLM"
4
+ ],
5
+ "auto_map": {
6
+ "AutoConfig": "configuration_setcon_lm.SetConLMConfig",
7
+ "AutoModel": "modeling_setcon_lm.SetConLM"
8
+ },
9
+ "base_model": "Qwen/Qwen3.5-0.8B",
10
+ "batch_size": 32,
11
+ "default_question": "What is the person doing?",
12
+ "encoder_hidden_size": 256,
13
+ "encoder_training_seed": 2,
14
+ "max_new_tokens": 48,
15
+ "model_type": "setcon_lm",
16
+ "num_patches": 50,
17
+ "num_sites": 22,
18
+ "site_text": [
19
+ "pelvis",
20
+ "left hip",
21
+ "left knee",
22
+ "left ankle",
23
+ "left foot",
24
+ "right hip",
25
+ "right knee",
26
+ "right ankle",
27
+ "right foot",
28
+ "spine",
29
+ "upper spine",
30
+ "chest",
31
+ "neck",
32
+ "head",
33
+ "left collar",
34
+ "left shoulder",
35
+ "left elbow",
36
+ "left wrist",
37
+ "right collar",
38
+ "right shoulder",
39
+ "right elbow",
40
+ "right wrist"
41
+ ],
42
+ "stop_tokens": [
43
+ "<|im_end|>",
44
+ "<|endoftext|>"
45
+ ],
46
+ "system_prompt": "Continuous tokens from sparse wearable IMUs are provided before this text. Answer the question about the observed motion in one or two short sentences.",
47
+ "text_config": {
48
+ "architectures": [
49
+ "Qwen3_5ForCausalLM"
50
+ ],
51
+ "attention_bias": false,
52
+ "attention_dropout": 0.0,
53
+ "attn_output_gate": true,
54
+ "bos_token_id": null,
55
+ "dtype": "float32",
56
+ "eos_token_id": 248044,
57
+ "full_attention_interval": 4,
58
+ "head_dim": 256,
59
+ "hidden_act": "silu",
60
+ "hidden_size": 1024,
61
+ "initializer_range": 0.02,
62
+ "intermediate_size": 3584,
63
+ "layer_types": [
64
+ "linear_attention",
65
+ "linear_attention",
66
+ "linear_attention",
67
+ "full_attention",
68
+ "linear_attention",
69
+ "linear_attention",
70
+ "linear_attention",
71
+ "full_attention",
72
+ "linear_attention",
73
+ "linear_attention",
74
+ "linear_attention",
75
+ "full_attention",
76
+ "linear_attention",
77
+ "linear_attention",
78
+ "linear_attention",
79
+ "full_attention",
80
+ "linear_attention",
81
+ "linear_attention",
82
+ "linear_attention",
83
+ "full_attention",
84
+ "linear_attention",
85
+ "linear_attention",
86
+ "linear_attention",
87
+ "full_attention"
88
+ ],
89
+ "linear_conv_kernel_dim": 4,
90
+ "linear_key_head_dim": 128,
91
+ "linear_num_key_heads": 16,
92
+ "linear_num_value_heads": 16,
93
+ "linear_value_head_dim": 128,
94
+ "mamba_ssm_dtype": "float32",
95
+ "max_position_embeddings": 262144,
96
+ "mlp_only_layers": [],
97
+ "model_type": "qwen3_5_text",
98
+ "mtp_num_hidden_layers": 1,
99
+ "mtp_use_dedicated_embeddings": false,
100
+ "num_attention_heads": 8,
101
+ "num_hidden_layers": 24,
102
+ "num_key_value_heads": 2,
103
+ "pad_token_id": null,
104
+ "partial_rotary_factor": 0.25,
105
+ "rms_norm_eps": 1e-06,
106
+ "rope_parameters": {
107
+ "mrope_interleaved": true,
108
+ "mrope_section": [
109
+ 11,
110
+ 11,
111
+ 10
112
+ ],
113
+ "partial_rotary_factor": 0.25,
114
+ "rope_theta": 10000000,
115
+ "rope_type": "default"
116
+ },
117
+ "tie_word_embeddings": true,
118
+ "use_cache": true,
119
+ "vocab_size": 248320
120
+ },
121
+ "transformers_version": "5.14.1"
122
+ }
lm/seed2/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
lm/seed2/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37483efb76a63c9697ab5497d889bed824125481c0fd769c523d4f4d2d93ce43
3
+ size 3020424668
lm/seed2/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f9e4d4901a92b997e463c1f46055088b6cca5ca61a6522d1b9f64c4bb81cb42
3
+ size 12807982
lm/seed2/tokenizer_config.json ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "248044": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "248045": {
13
+ "content": "<|im_start|>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "248046": {
21
+ "content": "<|im_end|>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "248047": {
29
+ "content": "<|object_ref_start|>",
30
+ "lstrip": false,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "248048": {
37
+ "content": "<|object_ref_end|>",
38
+ "lstrip": false,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ },
44
+ "248049": {
45
+ "content": "<|box_start|>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": true
51
+ },
52
+ "248050": {
53
+ "content": "<|box_end|>",
54
+ "lstrip": false,
55
+ "normalized": false,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": true
59
+ },
60
+ "248051": {
61
+ "content": "<|quad_start|>",
62
+ "lstrip": false,
63
+ "normalized": false,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": true
67
+ },
68
+ "248052": {
69
+ "content": "<|quad_end|>",
70
+ "lstrip": false,
71
+ "normalized": false,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": true
75
+ },
76
+ "248053": {
77
+ "content": "<|vision_start|>",
78
+ "lstrip": false,
79
+ "normalized": false,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": true
83
+ },
84
+ "248054": {
85
+ "content": "<|vision_end|>",
86
+ "lstrip": false,
87
+ "normalized": false,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": true
91
+ },
92
+ "248055": {
93
+ "content": "<|vision_pad|>",
94
+ "lstrip": false,
95
+ "normalized": false,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": true
99
+ },
100
+ "248056": {
101
+ "content": "<|image_pad|>",
102
+ "lstrip": false,
103
+ "normalized": false,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": true
107
+ },
108
+ "248057": {
109
+ "content": "<|video_pad|>",
110
+ "lstrip": false,
111
+ "normalized": false,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": true
115
+ },
116
+ "248058": {
117
+ "content": "<tool_call>",
118
+ "lstrip": false,
119
+ "normalized": false,
120
+ "rstrip": false,
121
+ "single_word": false,
122
+ "special": false
123
+ },
124
+ "248059": {
125
+ "content": "</tool_call>",
126
+ "lstrip": false,
127
+ "normalized": false,
128
+ "rstrip": false,
129
+ "single_word": false,
130
+ "special": false
131
+ },
132
+ "248060": {
133
+ "content": "<|fim_prefix|>",
134
+ "lstrip": false,
135
+ "normalized": false,
136
+ "rstrip": false,
137
+ "single_word": false,
138
+ "special": false
139
+ },
140
+ "248061": {
141
+ "content": "<|fim_middle|>",
142
+ "lstrip": false,
143
+ "normalized": false,
144
+ "rstrip": false,
145
+ "single_word": false,
146
+ "special": false
147
+ },
148
+ "248062": {
149
+ "content": "<|fim_suffix|>",
150
+ "lstrip": false,
151
+ "normalized": false,
152
+ "rstrip": false,
153
+ "single_word": false,
154
+ "special": false
155
+ },
156
+ "248063": {
157
+ "content": "<|fim_pad|>",
158
+ "lstrip": false,
159
+ "normalized": false,
160
+ "rstrip": false,
161
+ "single_word": false,
162
+ "special": false
163
+ },
164
+ "248064": {
165
+ "content": "<|repo_name|>",
166
+ "lstrip": false,
167
+ "normalized": false,
168
+ "rstrip": false,
169
+ "single_word": false,
170
+ "special": false
171
+ },
172
+ "248065": {
173
+ "content": "<|file_sep|>",
174
+ "lstrip": false,
175
+ "normalized": false,
176
+ "rstrip": false,
177
+ "single_word": false,
178
+ "special": false
179
+ },
180
+ "248066": {
181
+ "content": "<tool_response>",
182
+ "lstrip": false,
183
+ "normalized": false,
184
+ "rstrip": false,
185
+ "single_word": false,
186
+ "special": false
187
+ },
188
+ "248067": {
189
+ "content": "</tool_response>",
190
+ "lstrip": false,
191
+ "normalized": false,
192
+ "rstrip": false,
193
+ "single_word": false,
194
+ "special": false
195
+ },
196
+ "248068": {
197
+ "content": "<think>",
198
+ "lstrip": false,
199
+ "normalized": false,
200
+ "rstrip": false,
201
+ "single_word": false,
202
+ "special": false
203
+ },
204
+ "248069": {
205
+ "content": "</think>",
206
+ "lstrip": false,
207
+ "normalized": false,
208
+ "rstrip": false,
209
+ "single_word": false,
210
+ "special": false
211
+ },
212
+ "248070": {
213
+ "content": "<|audio_start|>",
214
+ "lstrip": false,
215
+ "normalized": false,
216
+ "rstrip": false,
217
+ "single_word": false,
218
+ "special": true
219
+ },
220
+ "248071": {
221
+ "content": "<|audio_end|>",
222
+ "lstrip": false,
223
+ "normalized": false,
224
+ "rstrip": false,
225
+ "single_word": false,
226
+ "special": true
227
+ },
228
+ "248072": {
229
+ "content": "<tts_pad>",
230
+ "lstrip": false,
231
+ "normalized": false,
232
+ "rstrip": false,
233
+ "single_word": false,
234
+ "special": true
235
+ },
236
+ "248073": {
237
+ "content": "<tts_text_bos>",
238
+ "lstrip": false,
239
+ "normalized": false,
240
+ "rstrip": false,
241
+ "single_word": false,
242
+ "special": true
243
+ },
244
+ "248074": {
245
+ "content": "<tts_text_eod>",
246
+ "lstrip": false,
247
+ "normalized": false,
248
+ "rstrip": false,
249
+ "single_word": false,
250
+ "special": true
251
+ },
252
+ "248075": {
253
+ "content": "<tts_text_bos_single>",
254
+ "lstrip": false,
255
+ "normalized": false,
256
+ "rstrip": false,
257
+ "single_word": false,
258
+ "special": true
259
+ },
260
+ "248076": {
261
+ "content": "<|audio_pad|>",
262
+ "lstrip": false,
263
+ "normalized": false,
264
+ "rstrip": false,
265
+ "single_word": false,
266
+ "special": true
267
+ }
268
+ },
269
+ "additional_special_tokens": [
270
+ "<|im_start|>",
271
+ "<|im_end|>",
272
+ "<|object_ref_start|>",
273
+ "<|object_ref_end|>",
274
+ "<|box_start|>",
275
+ "<|box_end|>",
276
+ "<|quad_start|>",
277
+ "<|quad_end|>",
278
+ "<|vision_start|>",
279
+ "<|vision_end|>",
280
+ "<|vision_pad|>",
281
+ "<|image_pad|>",
282
+ "<|video_pad|>"
283
+ ],
284
+ "bos_token": null,
285
+ "chat_template": "{%- set image_count = namespace(value=0) %}\n{%- set video_count = namespace(value=0) %}\n{%- macro render_content(content, do_vision_count, is_system_content=false) %}\n {%- if content is string %}\n {{- content }}\n {%- elif content is iterable and content is not mapping %}\n {%- for item in content %}\n {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain images.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set image_count.value = image_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Picture ' ~ image_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' }}\n {%- elif 'video' in item or item.type == 'video' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain videos.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set video_count.value = video_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Video ' ~ video_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' }}\n {%- elif 'text' in item %}\n {{- item.text }}\n {%- else %}\n {{- raise_exception('Unexpected item type in content.') }}\n {%- endif %}\n {%- endfor %}\n {%- elif content is none or content is undefined %}\n {{- '' }}\n {%- else %}\n {{- raise_exception('Unexpected content type.') }}\n {%- endif %}\n{%- endmacro %}\n{%- if not messages %}\n {{- raise_exception('No messages provided.') }}\n{%- endif %}\n{%- if tools and tools is iterable and tools is not mapping %}\n {{- '<|im_start|>system\\n' }}\n {{- \"# Tools\\n\\nYou have access to the following functions:\\n\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\" }}\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>\\nvalue_1\\n</parameter>\\n<parameter=example_parameter_2>\\nThis is the value for the second parameter\\nthat can span\\nmultiple lines\\n</parameter>\\n</function>\\n</tool_call>\\n\\n<IMPORTANT>\\nReminder:\\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\\n- Required parameters MUST be specified\\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\\n</IMPORTANT>' }}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {%- if content %}\n {{- '\\n\\n' + content }}\n {%- endif %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {{- '<|im_start|>system\\n' + content + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" %}\n {%- set content = render_content(message.content, false)|trim %}\n {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if ns.multi_step_tool %}\n {{- raise_exception('No user query found in messages.') }}\n{%- endif %}\n{%- for message in messages %}\n {%- set content = render_content(message.content, true)|trim %}\n {%- if message.role == \"system\" %}\n {%- if not loop.first %}\n {{- raise_exception('System message must be at the beginning.') }}\n {%- endif %}\n {%- elif message.role == \"user\" %}\n {{- '<|im_start|>' + message.role + '\\n' + content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- set content = content.split('</think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- set reasoning_content = reasoning_content|trim %}\n {%- if loop.index0 > ns.last_query_index %}\n {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content + '\\n</think>\\n\\n' + content }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {%- if loop.first %}\n {%- if content|trim %}\n {{- '\\n\\n<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- else %}\n {{- '<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- endif %}\n {%- if tool_call.arguments is defined %}\n {%- for args_name, args_value in tool_call.arguments|items %}\n {{- '<parameter=' + args_name + '>\\n' }}\n {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}\n {{- args_value }}\n {{- '\\n</parameter>\\n' }}\n {%- endfor %}\n {%- endif %}\n {{- '</function>\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.previtem and loop.previtem.role != \"tool\" %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content }}\n {{- '\\n</tool_response>' }}\n {%- if not loop.last and loop.nextitem.role != \"tool\" %}\n {{- '<|im_end|>\\n' }}\n {%- elif loop.last %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- else %}\n {{- raise_exception('Unexpected message role.') }}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if enable_thinking is defined and enable_thinking is true %}\n {{- '<think>\\n' }}\n {%- else %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- endif %}\n{%- endif %}",
286
+ "clean_up_tokenization_spaces": false,
287
+ "eos_token": "<|im_end|>",
288
+ "errors": "replace",
289
+ "model_max_length": 262144,
290
+ "pad_token": "<|endoftext|>",
291
+ "split_special_tokens": false,
292
+ "tokenizer_class": "Qwen2Tokenizer",
293
+ "unk_token": null,
294
+ "add_bos_token": false,
295
+ "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
296
+ "extra_special_tokens": {
297
+ "audio_bos_token": "<|audio_start|>",
298
+ "audio_eos_token": "<|audio_end|>",
299
+ "audio_token": "<|audio_pad|>",
300
+ "image_token": "<|image_pad|>",
301
+ "video_token": "<|video_pad|>",
302
+ "vision_bos_token": "<|vision_start|>",
303
+ "vision_eos_token": "<|vision_end|>"
304
+ }
305
+ }
lm/seed2/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
lm/seed3/chat_template.jinja ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- set image_count = namespace(value=0) %}
2
+ {%- set video_count = namespace(value=0) %}
3
+ {%- macro render_content(content, do_vision_count, is_system_content=false) %}
4
+ {%- if content is string %}
5
+ {{- content }}
6
+ {%- elif content is iterable and content is not mapping %}
7
+ {%- for item in content %}
8
+ {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
9
+ {%- if is_system_content %}
10
+ {{- raise_exception('System message cannot contain images.') }}
11
+ {%- endif %}
12
+ {%- if do_vision_count %}
13
+ {%- set image_count.value = image_count.value + 1 %}
14
+ {%- endif %}
15
+ {%- if add_vision_id %}
16
+ {{- 'Picture ' ~ image_count.value ~ ': ' }}
17
+ {%- endif %}
18
+ {{- '<|vision_start|><|image_pad|><|vision_end|>' }}
19
+ {%- elif 'video' in item or item.type == 'video' %}
20
+ {%- if is_system_content %}
21
+ {{- raise_exception('System message cannot contain videos.') }}
22
+ {%- endif %}
23
+ {%- if do_vision_count %}
24
+ {%- set video_count.value = video_count.value + 1 %}
25
+ {%- endif %}
26
+ {%- if add_vision_id %}
27
+ {{- 'Video ' ~ video_count.value ~ ': ' }}
28
+ {%- endif %}
29
+ {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
30
+ {%- elif 'text' in item %}
31
+ {{- item.text }}
32
+ {%- else %}
33
+ {{- raise_exception('Unexpected item type in content.') }}
34
+ {%- endif %}
35
+ {%- endfor %}
36
+ {%- elif content is none or content is undefined %}
37
+ {{- '' }}
38
+ {%- else %}
39
+ {{- raise_exception('Unexpected content type.') }}
40
+ {%- endif %}
41
+ {%- endmacro %}
42
+ {%- if not messages %}
43
+ {{- raise_exception('No messages provided.') }}
44
+ {%- endif %}
45
+ {%- if tools and tools is iterable and tools is not mapping %}
46
+ {{- '<|im_start|>system\n' }}
47
+ {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
48
+ {%- for tool in tools %}
49
+ {{- "\n" }}
50
+ {{- tool | tojson }}
51
+ {%- endfor %}
52
+ {{- "\n</tools>" }}
53
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
54
+ {%- if messages[0].role == 'system' %}
55
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
56
+ {%- if content %}
57
+ {{- '\n\n' + content }}
58
+ {%- endif %}
59
+ {%- endif %}
60
+ {{- '<|im_end|>\n' }}
61
+ {%- else %}
62
+ {%- if messages[0].role == 'system' %}
63
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
64
+ {{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
65
+ {%- endif %}
66
+ {%- endif %}
67
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
68
+ {%- for message in messages[::-1] %}
69
+ {%- set index = (messages|length - 1) - loop.index0 %}
70
+ {%- if ns.multi_step_tool and message.role == "user" %}
71
+ {%- set content = render_content(message.content, false)|trim %}
72
+ {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
73
+ {%- set ns.multi_step_tool = false %}
74
+ {%- set ns.last_query_index = index %}
75
+ {%- endif %}
76
+ {%- endif %}
77
+ {%- endfor %}
78
+ {%- if ns.multi_step_tool %}
79
+ {{- raise_exception('No user query found in messages.') }}
80
+ {%- endif %}
81
+ {%- for message in messages %}
82
+ {%- set content = render_content(message.content, true)|trim %}
83
+ {%- if message.role == "system" %}
84
+ {%- if not loop.first %}
85
+ {{- raise_exception('System message must be at the beginning.') }}
86
+ {%- endif %}
87
+ {%- elif message.role == "user" %}
88
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
89
+ {%- elif message.role == "assistant" %}
90
+ {%- set reasoning_content = '' %}
91
+ {%- if message.reasoning_content is string %}
92
+ {%- set reasoning_content = message.reasoning_content %}
93
+ {%- else %}
94
+ {%- if '</think>' in content %}
95
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
96
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
97
+ {%- endif %}
98
+ {%- endif %}
99
+ {%- set reasoning_content = reasoning_content|trim %}
100
+ {%- if loop.index0 > ns.last_query_index %}
101
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
102
+ {%- else %}
103
+ {{- '<|im_start|>' + message.role + '\n' + content }}
104
+ {%- endif %}
105
+ {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
106
+ {%- for tool_call in message.tool_calls %}
107
+ {%- if tool_call.function is defined %}
108
+ {%- set tool_call = tool_call.function %}
109
+ {%- endif %}
110
+ {%- if loop.first %}
111
+ {%- if content|trim %}
112
+ {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
113
+ {%- else %}
114
+ {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
115
+ {%- endif %}
116
+ {%- else %}
117
+ {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
118
+ {%- endif %}
119
+ {%- if tool_call.arguments is defined %}
120
+ {%- for args_name, args_value in tool_call.arguments|items %}
121
+ {{- '<parameter=' + args_name + '>\n' }}
122
+ {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
123
+ {{- args_value }}
124
+ {{- '\n</parameter>\n' }}
125
+ {%- endfor %}
126
+ {%- endif %}
127
+ {{- '</function>\n</tool_call>' }}
128
+ {%- endfor %}
129
+ {%- endif %}
130
+ {{- '<|im_end|>\n' }}
131
+ {%- elif message.role == "tool" %}
132
+ {%- if loop.previtem and loop.previtem.role != "tool" %}
133
+ {{- '<|im_start|>user' }}
134
+ {%- endif %}
135
+ {{- '\n<tool_response>\n' }}
136
+ {{- content }}
137
+ {{- '\n</tool_response>' }}
138
+ {%- if not loop.last and loop.nextitem.role != "tool" %}
139
+ {{- '<|im_end|>\n' }}
140
+ {%- elif loop.last %}
141
+ {{- '<|im_end|>\n' }}
142
+ {%- endif %}
143
+ {%- else %}
144
+ {{- raise_exception('Unexpected message role.') }}
145
+ {%- endif %}
146
+ {%- endfor %}
147
+ {%- if add_generation_prompt %}
148
+ {{- '<|im_start|>assistant\n' }}
149
+ {%- if enable_thinking is defined and enable_thinking is true %}
150
+ {{- '<think>\n' }}
151
+ {%- else %}
152
+ {{- '<think>\n\n</think>\n\n' }}
153
+ {%- endif %}
154
+ {%- endif %}
lm/seed3/config.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "SetConLM"
4
+ ],
5
+ "auto_map": {
6
+ "AutoConfig": "configuration_setcon_lm.SetConLMConfig",
7
+ "AutoModel": "modeling_setcon_lm.SetConLM"
8
+ },
9
+ "base_model": "Qwen/Qwen3.5-0.8B",
10
+ "batch_size": 32,
11
+ "default_question": "What is the person doing?",
12
+ "encoder_hidden_size": 256,
13
+ "encoder_training_seed": 3,
14
+ "max_new_tokens": 48,
15
+ "model_type": "setcon_lm",
16
+ "num_patches": 50,
17
+ "num_sites": 22,
18
+ "site_text": [
19
+ "pelvis",
20
+ "left hip",
21
+ "left knee",
22
+ "left ankle",
23
+ "left foot",
24
+ "right hip",
25
+ "right knee",
26
+ "right ankle",
27
+ "right foot",
28
+ "spine",
29
+ "upper spine",
30
+ "chest",
31
+ "neck",
32
+ "head",
33
+ "left collar",
34
+ "left shoulder",
35
+ "left elbow",
36
+ "left wrist",
37
+ "right collar",
38
+ "right shoulder",
39
+ "right elbow",
40
+ "right wrist"
41
+ ],
42
+ "stop_tokens": [
43
+ "<|im_end|>",
44
+ "<|endoftext|>"
45
+ ],
46
+ "system_prompt": "Continuous tokens from sparse wearable IMUs are provided before this text. Answer the question about the observed motion in one or two short sentences.",
47
+ "text_config": {
48
+ "architectures": [
49
+ "Qwen3_5ForCausalLM"
50
+ ],
51
+ "attention_bias": false,
52
+ "attention_dropout": 0.0,
53
+ "attn_output_gate": true,
54
+ "bos_token_id": null,
55
+ "dtype": "float32",
56
+ "eos_token_id": 248044,
57
+ "full_attention_interval": 4,
58
+ "head_dim": 256,
59
+ "hidden_act": "silu",
60
+ "hidden_size": 1024,
61
+ "initializer_range": 0.02,
62
+ "intermediate_size": 3584,
63
+ "layer_types": [
64
+ "linear_attention",
65
+ "linear_attention",
66
+ "linear_attention",
67
+ "full_attention",
68
+ "linear_attention",
69
+ "linear_attention",
70
+ "linear_attention",
71
+ "full_attention",
72
+ "linear_attention",
73
+ "linear_attention",
74
+ "linear_attention",
75
+ "full_attention",
76
+ "linear_attention",
77
+ "linear_attention",
78
+ "linear_attention",
79
+ "full_attention",
80
+ "linear_attention",
81
+ "linear_attention",
82
+ "linear_attention",
83
+ "full_attention",
84
+ "linear_attention",
85
+ "linear_attention",
86
+ "linear_attention",
87
+ "full_attention"
88
+ ],
89
+ "linear_conv_kernel_dim": 4,
90
+ "linear_key_head_dim": 128,
91
+ "linear_num_key_heads": 16,
92
+ "linear_num_value_heads": 16,
93
+ "linear_value_head_dim": 128,
94
+ "mamba_ssm_dtype": "float32",
95
+ "max_position_embeddings": 262144,
96
+ "mlp_only_layers": [],
97
+ "model_type": "qwen3_5_text",
98
+ "mtp_num_hidden_layers": 1,
99
+ "mtp_use_dedicated_embeddings": false,
100
+ "num_attention_heads": 8,
101
+ "num_hidden_layers": 24,
102
+ "num_key_value_heads": 2,
103
+ "pad_token_id": null,
104
+ "partial_rotary_factor": 0.25,
105
+ "rms_norm_eps": 1e-06,
106
+ "rope_parameters": {
107
+ "mrope_interleaved": true,
108
+ "mrope_section": [
109
+ 11,
110
+ 11,
111
+ 10
112
+ ],
113
+ "partial_rotary_factor": 0.25,
114
+ "rope_theta": 10000000,
115
+ "rope_type": "default"
116
+ },
117
+ "tie_word_embeddings": true,
118
+ "use_cache": true,
119
+ "vocab_size": 248320
120
+ },
121
+ "transformers_version": "5.14.1"
122
+ }
lm/seed3/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
lm/seed3/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb89bcfbd4518b080ec5d440b58f1c87a5dfdbba1cd3e866fb2d1e0594aadc63
3
+ size 3020424668
lm/seed3/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f9e4d4901a92b997e463c1f46055088b6cca5ca61a6522d1b9f64c4bb81cb42
3
+ size 12807982
lm/seed3/tokenizer_config.json ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "248044": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "248045": {
13
+ "content": "<|im_start|>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "248046": {
21
+ "content": "<|im_end|>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "248047": {
29
+ "content": "<|object_ref_start|>",
30
+ "lstrip": false,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "248048": {
37
+ "content": "<|object_ref_end|>",
38
+ "lstrip": false,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ },
44
+ "248049": {
45
+ "content": "<|box_start|>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": true
51
+ },
52
+ "248050": {
53
+ "content": "<|box_end|>",
54
+ "lstrip": false,
55
+ "normalized": false,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": true
59
+ },
60
+ "248051": {
61
+ "content": "<|quad_start|>",
62
+ "lstrip": false,
63
+ "normalized": false,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": true
67
+ },
68
+ "248052": {
69
+ "content": "<|quad_end|>",
70
+ "lstrip": false,
71
+ "normalized": false,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": true
75
+ },
76
+ "248053": {
77
+ "content": "<|vision_start|>",
78
+ "lstrip": false,
79
+ "normalized": false,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": true
83
+ },
84
+ "248054": {
85
+ "content": "<|vision_end|>",
86
+ "lstrip": false,
87
+ "normalized": false,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": true
91
+ },
92
+ "248055": {
93
+ "content": "<|vision_pad|>",
94
+ "lstrip": false,
95
+ "normalized": false,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": true
99
+ },
100
+ "248056": {
101
+ "content": "<|image_pad|>",
102
+ "lstrip": false,
103
+ "normalized": false,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": true
107
+ },
108
+ "248057": {
109
+ "content": "<|video_pad|>",
110
+ "lstrip": false,
111
+ "normalized": false,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": true
115
+ },
116
+ "248058": {
117
+ "content": "<tool_call>",
118
+ "lstrip": false,
119
+ "normalized": false,
120
+ "rstrip": false,
121
+ "single_word": false,
122
+ "special": false
123
+ },
124
+ "248059": {
125
+ "content": "</tool_call>",
126
+ "lstrip": false,
127
+ "normalized": false,
128
+ "rstrip": false,
129
+ "single_word": false,
130
+ "special": false
131
+ },
132
+ "248060": {
133
+ "content": "<|fim_prefix|>",
134
+ "lstrip": false,
135
+ "normalized": false,
136
+ "rstrip": false,
137
+ "single_word": false,
138
+ "special": false
139
+ },
140
+ "248061": {
141
+ "content": "<|fim_middle|>",
142
+ "lstrip": false,
143
+ "normalized": false,
144
+ "rstrip": false,
145
+ "single_word": false,
146
+ "special": false
147
+ },
148
+ "248062": {
149
+ "content": "<|fim_suffix|>",
150
+ "lstrip": false,
151
+ "normalized": false,
152
+ "rstrip": false,
153
+ "single_word": false,
154
+ "special": false
155
+ },
156
+ "248063": {
157
+ "content": "<|fim_pad|>",
158
+ "lstrip": false,
159
+ "normalized": false,
160
+ "rstrip": false,
161
+ "single_word": false,
162
+ "special": false
163
+ },
164
+ "248064": {
165
+ "content": "<|repo_name|>",
166
+ "lstrip": false,
167
+ "normalized": false,
168
+ "rstrip": false,
169
+ "single_word": false,
170
+ "special": false
171
+ },
172
+ "248065": {
173
+ "content": "<|file_sep|>",
174
+ "lstrip": false,
175
+ "normalized": false,
176
+ "rstrip": false,
177
+ "single_word": false,
178
+ "special": false
179
+ },
180
+ "248066": {
181
+ "content": "<tool_response>",
182
+ "lstrip": false,
183
+ "normalized": false,
184
+ "rstrip": false,
185
+ "single_word": false,
186
+ "special": false
187
+ },
188
+ "248067": {
189
+ "content": "</tool_response>",
190
+ "lstrip": false,
191
+ "normalized": false,
192
+ "rstrip": false,
193
+ "single_word": false,
194
+ "special": false
195
+ },
196
+ "248068": {
197
+ "content": "<think>",
198
+ "lstrip": false,
199
+ "normalized": false,
200
+ "rstrip": false,
201
+ "single_word": false,
202
+ "special": false
203
+ },
204
+ "248069": {
205
+ "content": "</think>",
206
+ "lstrip": false,
207
+ "normalized": false,
208
+ "rstrip": false,
209
+ "single_word": false,
210
+ "special": false
211
+ },
212
+ "248070": {
213
+ "content": "<|audio_start|>",
214
+ "lstrip": false,
215
+ "normalized": false,
216
+ "rstrip": false,
217
+ "single_word": false,
218
+ "special": true
219
+ },
220
+ "248071": {
221
+ "content": "<|audio_end|>",
222
+ "lstrip": false,
223
+ "normalized": false,
224
+ "rstrip": false,
225
+ "single_word": false,
226
+ "special": true
227
+ },
228
+ "248072": {
229
+ "content": "<tts_pad>",
230
+ "lstrip": false,
231
+ "normalized": false,
232
+ "rstrip": false,
233
+ "single_word": false,
234
+ "special": true
235
+ },
236
+ "248073": {
237
+ "content": "<tts_text_bos>",
238
+ "lstrip": false,
239
+ "normalized": false,
240
+ "rstrip": false,
241
+ "single_word": false,
242
+ "special": true
243
+ },
244
+ "248074": {
245
+ "content": "<tts_text_eod>",
246
+ "lstrip": false,
247
+ "normalized": false,
248
+ "rstrip": false,
249
+ "single_word": false,
250
+ "special": true
251
+ },
252
+ "248075": {
253
+ "content": "<tts_text_bos_single>",
254
+ "lstrip": false,
255
+ "normalized": false,
256
+ "rstrip": false,
257
+ "single_word": false,
258
+ "special": true
259
+ },
260
+ "248076": {
261
+ "content": "<|audio_pad|>",
262
+ "lstrip": false,
263
+ "normalized": false,
264
+ "rstrip": false,
265
+ "single_word": false,
266
+ "special": true
267
+ }
268
+ },
269
+ "additional_special_tokens": [
270
+ "<|im_start|>",
271
+ "<|im_end|>",
272
+ "<|object_ref_start|>",
273
+ "<|object_ref_end|>",
274
+ "<|box_start|>",
275
+ "<|box_end|>",
276
+ "<|quad_start|>",
277
+ "<|quad_end|>",
278
+ "<|vision_start|>",
279
+ "<|vision_end|>",
280
+ "<|vision_pad|>",
281
+ "<|image_pad|>",
282
+ "<|video_pad|>"
283
+ ],
284
+ "bos_token": null,
285
+ "chat_template": "{%- set image_count = namespace(value=0) %}\n{%- set video_count = namespace(value=0) %}\n{%- macro render_content(content, do_vision_count, is_system_content=false) %}\n {%- if content is string %}\n {{- content }}\n {%- elif content is iterable and content is not mapping %}\n {%- for item in content %}\n {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain images.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set image_count.value = image_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Picture ' ~ image_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' }}\n {%- elif 'video' in item or item.type == 'video' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain videos.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set video_count.value = video_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Video ' ~ video_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' }}\n {%- elif 'text' in item %}\n {{- item.text }}\n {%- else %}\n {{- raise_exception('Unexpected item type in content.') }}\n {%- endif %}\n {%- endfor %}\n {%- elif content is none or content is undefined %}\n {{- '' }}\n {%- else %}\n {{- raise_exception('Unexpected content type.') }}\n {%- endif %}\n{%- endmacro %}\n{%- if not messages %}\n {{- raise_exception('No messages provided.') }}\n{%- endif %}\n{%- if tools and tools is iterable and tools is not mapping %}\n {{- '<|im_start|>system\\n' }}\n {{- \"# Tools\\n\\nYou have access to the following functions:\\n\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\" }}\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>\\nvalue_1\\n</parameter>\\n<parameter=example_parameter_2>\\nThis is the value for the second parameter\\nthat can span\\nmultiple lines\\n</parameter>\\n</function>\\n</tool_call>\\n\\n<IMPORTANT>\\nReminder:\\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\\n- Required parameters MUST be specified\\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\\n</IMPORTANT>' }}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {%- if content %}\n {{- '\\n\\n' + content }}\n {%- endif %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {{- '<|im_start|>system\\n' + content + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" %}\n {%- set content = render_content(message.content, false)|trim %}\n {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if ns.multi_step_tool %}\n {{- raise_exception('No user query found in messages.') }}\n{%- endif %}\n{%- for message in messages %}\n {%- set content = render_content(message.content, true)|trim %}\n {%- if message.role == \"system\" %}\n {%- if not loop.first %}\n {{- raise_exception('System message must be at the beginning.') }}\n {%- endif %}\n {%- elif message.role == \"user\" %}\n {{- '<|im_start|>' + message.role + '\\n' + content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- set content = content.split('</think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- set reasoning_content = reasoning_content|trim %}\n {%- if loop.index0 > ns.last_query_index %}\n {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content + '\\n</think>\\n\\n' + content }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {%- if loop.first %}\n {%- if content|trim %}\n {{- '\\n\\n<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- else %}\n {{- '<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- endif %}\n {%- if tool_call.arguments is defined %}\n {%- for args_name, args_value in tool_call.arguments|items %}\n {{- '<parameter=' + args_name + '>\\n' }}\n {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}\n {{- args_value }}\n {{- '\\n</parameter>\\n' }}\n {%- endfor %}\n {%- endif %}\n {{- '</function>\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.previtem and loop.previtem.role != \"tool\" %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content }}\n {{- '\\n</tool_response>' }}\n {%- if not loop.last and loop.nextitem.role != \"tool\" %}\n {{- '<|im_end|>\\n' }}\n {%- elif loop.last %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- else %}\n {{- raise_exception('Unexpected message role.') }}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if enable_thinking is defined and enable_thinking is true %}\n {{- '<think>\\n' }}\n {%- else %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- endif %}\n{%- endif %}",
286
+ "clean_up_tokenization_spaces": false,
287
+ "eos_token": "<|im_end|>",
288
+ "errors": "replace",
289
+ "model_max_length": 262144,
290
+ "pad_token": "<|endoftext|>",
291
+ "split_special_tokens": false,
292
+ "tokenizer_class": "Qwen2Tokenizer",
293
+ "unk_token": null,
294
+ "add_bos_token": false,
295
+ "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
296
+ "extra_special_tokens": {
297
+ "audio_bos_token": "<|audio_start|>",
298
+ "audio_eos_token": "<|audio_end|>",
299
+ "audio_token": "<|audio_pad|>",
300
+ "image_token": "<|image_pad|>",
301
+ "video_token": "<|video_pad|>",
302
+ "vision_bos_token": "<|vision_start|>",
303
+ "vision_eos_token": "<|vision_end|>"
304
+ }
305
+ }
lm/seed3/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
lm/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f9e4d4901a92b997e463c1f46055088b6cca5ca61a6522d1b9f64c4bb81cb42
3
+ size 12807982
lm/tokenizer_config.json ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "248044": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "248045": {
13
+ "content": "<|im_start|>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "248046": {
21
+ "content": "<|im_end|>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "248047": {
29
+ "content": "<|object_ref_start|>",
30
+ "lstrip": false,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "248048": {
37
+ "content": "<|object_ref_end|>",
38
+ "lstrip": false,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ },
44
+ "248049": {
45
+ "content": "<|box_start|>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": true
51
+ },
52
+ "248050": {
53
+ "content": "<|box_end|>",
54
+ "lstrip": false,
55
+ "normalized": false,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": true
59
+ },
60
+ "248051": {
61
+ "content": "<|quad_start|>",
62
+ "lstrip": false,
63
+ "normalized": false,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": true
67
+ },
68
+ "248052": {
69
+ "content": "<|quad_end|>",
70
+ "lstrip": false,
71
+ "normalized": false,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": true
75
+ },
76
+ "248053": {
77
+ "content": "<|vision_start|>",
78
+ "lstrip": false,
79
+ "normalized": false,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": true
83
+ },
84
+ "248054": {
85
+ "content": "<|vision_end|>",
86
+ "lstrip": false,
87
+ "normalized": false,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": true
91
+ },
92
+ "248055": {
93
+ "content": "<|vision_pad|>",
94
+ "lstrip": false,
95
+ "normalized": false,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": true
99
+ },
100
+ "248056": {
101
+ "content": "<|image_pad|>",
102
+ "lstrip": false,
103
+ "normalized": false,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": true
107
+ },
108
+ "248057": {
109
+ "content": "<|video_pad|>",
110
+ "lstrip": false,
111
+ "normalized": false,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": true
115
+ },
116
+ "248058": {
117
+ "content": "<tool_call>",
118
+ "lstrip": false,
119
+ "normalized": false,
120
+ "rstrip": false,
121
+ "single_word": false,
122
+ "special": false
123
+ },
124
+ "248059": {
125
+ "content": "</tool_call>",
126
+ "lstrip": false,
127
+ "normalized": false,
128
+ "rstrip": false,
129
+ "single_word": false,
130
+ "special": false
131
+ },
132
+ "248060": {
133
+ "content": "<|fim_prefix|>",
134
+ "lstrip": false,
135
+ "normalized": false,
136
+ "rstrip": false,
137
+ "single_word": false,
138
+ "special": false
139
+ },
140
+ "248061": {
141
+ "content": "<|fim_middle|>",
142
+ "lstrip": false,
143
+ "normalized": false,
144
+ "rstrip": false,
145
+ "single_word": false,
146
+ "special": false
147
+ },
148
+ "248062": {
149
+ "content": "<|fim_suffix|>",
150
+ "lstrip": false,
151
+ "normalized": false,
152
+ "rstrip": false,
153
+ "single_word": false,
154
+ "special": false
155
+ },
156
+ "248063": {
157
+ "content": "<|fim_pad|>",
158
+ "lstrip": false,
159
+ "normalized": false,
160
+ "rstrip": false,
161
+ "single_word": false,
162
+ "special": false
163
+ },
164
+ "248064": {
165
+ "content": "<|repo_name|>",
166
+ "lstrip": false,
167
+ "normalized": false,
168
+ "rstrip": false,
169
+ "single_word": false,
170
+ "special": false
171
+ },
172
+ "248065": {
173
+ "content": "<|file_sep|>",
174
+ "lstrip": false,
175
+ "normalized": false,
176
+ "rstrip": false,
177
+ "single_word": false,
178
+ "special": false
179
+ },
180
+ "248066": {
181
+ "content": "<tool_response>",
182
+ "lstrip": false,
183
+ "normalized": false,
184
+ "rstrip": false,
185
+ "single_word": false,
186
+ "special": false
187
+ },
188
+ "248067": {
189
+ "content": "</tool_response>",
190
+ "lstrip": false,
191
+ "normalized": false,
192
+ "rstrip": false,
193
+ "single_word": false,
194
+ "special": false
195
+ },
196
+ "248068": {
197
+ "content": "<think>",
198
+ "lstrip": false,
199
+ "normalized": false,
200
+ "rstrip": false,
201
+ "single_word": false,
202
+ "special": false
203
+ },
204
+ "248069": {
205
+ "content": "</think>",
206
+ "lstrip": false,
207
+ "normalized": false,
208
+ "rstrip": false,
209
+ "single_word": false,
210
+ "special": false
211
+ },
212
+ "248070": {
213
+ "content": "<|audio_start|>",
214
+ "lstrip": false,
215
+ "normalized": false,
216
+ "rstrip": false,
217
+ "single_word": false,
218
+ "special": true
219
+ },
220
+ "248071": {
221
+ "content": "<|audio_end|>",
222
+ "lstrip": false,
223
+ "normalized": false,
224
+ "rstrip": false,
225
+ "single_word": false,
226
+ "special": true
227
+ },
228
+ "248072": {
229
+ "content": "<tts_pad>",
230
+ "lstrip": false,
231
+ "normalized": false,
232
+ "rstrip": false,
233
+ "single_word": false,
234
+ "special": true
235
+ },
236
+ "248073": {
237
+ "content": "<tts_text_bos>",
238
+ "lstrip": false,
239
+ "normalized": false,
240
+ "rstrip": false,
241
+ "single_word": false,
242
+ "special": true
243
+ },
244
+ "248074": {
245
+ "content": "<tts_text_eod>",
246
+ "lstrip": false,
247
+ "normalized": false,
248
+ "rstrip": false,
249
+ "single_word": false,
250
+ "special": true
251
+ },
252
+ "248075": {
253
+ "content": "<tts_text_bos_single>",
254
+ "lstrip": false,
255
+ "normalized": false,
256
+ "rstrip": false,
257
+ "single_word": false,
258
+ "special": true
259
+ },
260
+ "248076": {
261
+ "content": "<|audio_pad|>",
262
+ "lstrip": false,
263
+ "normalized": false,
264
+ "rstrip": false,
265
+ "single_word": false,
266
+ "special": true
267
+ }
268
+ },
269
+ "additional_special_tokens": [
270
+ "<|im_start|>",
271
+ "<|im_end|>",
272
+ "<|object_ref_start|>",
273
+ "<|object_ref_end|>",
274
+ "<|box_start|>",
275
+ "<|box_end|>",
276
+ "<|quad_start|>",
277
+ "<|quad_end|>",
278
+ "<|vision_start|>",
279
+ "<|vision_end|>",
280
+ "<|vision_pad|>",
281
+ "<|image_pad|>",
282
+ "<|video_pad|>"
283
+ ],
284
+ "bos_token": null,
285
+ "chat_template": "{%- set image_count = namespace(value=0) %}\n{%- set video_count = namespace(value=0) %}\n{%- macro render_content(content, do_vision_count, is_system_content=false) %}\n {%- if content is string %}\n {{- content }}\n {%- elif content is iterable and content is not mapping %}\n {%- for item in content %}\n {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain images.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set image_count.value = image_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Picture ' ~ image_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' }}\n {%- elif 'video' in item or item.type == 'video' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain videos.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set video_count.value = video_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Video ' ~ video_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' }}\n {%- elif 'text' in item %}\n {{- item.text }}\n {%- else %}\n {{- raise_exception('Unexpected item type in content.') }}\n {%- endif %}\n {%- endfor %}\n {%- elif content is none or content is undefined %}\n {{- '' }}\n {%- else %}\n {{- raise_exception('Unexpected content type.') }}\n {%- endif %}\n{%- endmacro %}\n{%- if not messages %}\n {{- raise_exception('No messages provided.') }}\n{%- endif %}\n{%- if tools and tools is iterable and tools is not mapping %}\n {{- '<|im_start|>system\\n' }}\n {{- \"# Tools\\n\\nYou have access to the following functions:\\n\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\" }}\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>\\nvalue_1\\n</parameter>\\n<parameter=example_parameter_2>\\nThis is the value for the second parameter\\nthat can span\\nmultiple lines\\n</parameter>\\n</function>\\n</tool_call>\\n\\n<IMPORTANT>\\nReminder:\\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\\n- Required parameters MUST be specified\\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\\n</IMPORTANT>' }}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {%- if content %}\n {{- '\\n\\n' + content }}\n {%- endif %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {{- '<|im_start|>system\\n' + content + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" %}\n {%- set content = render_content(message.content, false)|trim %}\n {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if ns.multi_step_tool %}\n {{- raise_exception('No user query found in messages.') }}\n{%- endif %}\n{%- for message in messages %}\n {%- set content = render_content(message.content, true)|trim %}\n {%- if message.role == \"system\" %}\n {%- if not loop.first %}\n {{- raise_exception('System message must be at the beginning.') }}\n {%- endif %}\n {%- elif message.role == \"user\" %}\n {{- '<|im_start|>' + message.role + '\\n' + content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- set content = content.split('</think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- set reasoning_content = reasoning_content|trim %}\n {%- if loop.index0 > ns.last_query_index %}\n {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content + '\\n</think>\\n\\n' + content }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {%- if loop.first %}\n {%- if content|trim %}\n {{- '\\n\\n<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- else %}\n {{- '<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- endif %}\n {%- if tool_call.arguments is defined %}\n {%- for args_name, args_value in tool_call.arguments|items %}\n {{- '<parameter=' + args_name + '>\\n' }}\n {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}\n {{- args_value }}\n {{- '\\n</parameter>\\n' }}\n {%- endfor %}\n {%- endif %}\n {{- '</function>\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.previtem and loop.previtem.role != \"tool\" %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content }}\n {{- '\\n</tool_response>' }}\n {%- if not loop.last and loop.nextitem.role != \"tool\" %}\n {{- '<|im_end|>\\n' }}\n {%- elif loop.last %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- else %}\n {{- raise_exception('Unexpected message role.') }}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if enable_thinking is defined and enable_thinking is true %}\n {{- '<think>\\n' }}\n {%- else %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- endif %}\n{%- endif %}",
286
+ "clean_up_tokenization_spaces": false,
287
+ "eos_token": "<|im_end|>",
288
+ "errors": "replace",
289
+ "model_max_length": 262144,
290
+ "pad_token": "<|endoftext|>",
291
+ "split_special_tokens": false,
292
+ "tokenizer_class": "Qwen2Tokenizer",
293
+ "unk_token": null,
294
+ "add_bos_token": false,
295
+ "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
296
+ "extra_special_tokens": {
297
+ "audio_bos_token": "<|audio_start|>",
298
+ "audio_eos_token": "<|audio_end|>",
299
+ "audio_token": "<|audio_pad|>",
300
+ "image_token": "<|image_pad|>",
301
+ "video_token": "<|video_pad|>",
302
+ "vision_bos_token": "<|vision_start|>",
303
+ "vision_eos_token": "<|vision_end|>"
304
+ }
305
+ }
lm/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
modeling_setcon_lm.py ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """SetCon-LM: Qwen3.5-0.8B answering questions about IMU windows, on top of the frozen SetCon encoder (Hugging Face
2
+ remote code, inference only, transformers >= 5).
3
+
4
+ setcon = AutoModel.from_pretrained("<repo>", trust_remote_code=True) # encoder, seed 1
5
+ lm = AutoModel.from_pretrained("<repo>", subfolder="lm", trust_remote_code=True) # its language model
6
+ lm.ask(setcon, windows, "What is the person doing?")
7
+
8
+ Seeds 2 and 3: encoder subfolder="seed2" with LM subfolder="lm/seed2" (and the same for seed 3). Each LM was trained
9
+ on one encoder checkpoint and refuses another one.
10
+
11
+ How a window reaches the language model (paper Sec. 3.6):
12
+ 1. The windows carry the setup reference of their device in channels 6-8, as for zero-shot classification
13
+ (processing_setcon.set_reference with SetConModel.estimate_reference on six unlabeled windows of the device).
14
+ 2. The frozen encoder runs once. Its setup vector (a linear map of the worn-site and gyroscope flags) gives one
15
+ token, and every worn site x valid 0.2-s patch gives one token (at most 1 + 22 x 50).
16
+ 3. The projector maps each to the LM's width: two-layer MLP, plus learned site, patch-time and token-type
17
+ embeddings for the patch tokens, then LayerNorm and a learned scale.
18
+ 4. These vectors precede the chat prompt: the system prompt, then "Sensors worn at: <sites>." and the question
19
+ (Qwen3.5 chat template, thinking off).
20
+ 5. Greedy decoding stops at <|im_end|> or <|endoftext|>.
21
+
22
+ Settings of the paper's evaluation: encoder and projector under bfloat16 autocast on CUDA, the language model in
23
+ float32 without autocast, batches of 32 windows (left padding), at most 48 new tokens.
24
+ """
25
+ from __future__ import annotations
26
+
27
+ import os
28
+
29
+ os.environ.setdefault("FLA_DISABLE_BACKEND_DISPATCH", "1") # see configuration_setcon_lm.py; before fla is imported
30
+
31
+ import numpy as np # noqa: E402
32
+ import torch # noqa: E402
33
+ import torch.nn as nn # noqa: E402
34
+ import torch.nn.functional as F # noqa: E402
35
+ from transformers import PreTrainedModel, Qwen2Tokenizer # noqa: E402
36
+ from transformers.models.qwen3_5.modeling_qwen3_5 import Qwen3_5ForCausalLM # noqa: E402
37
+
38
+ from .configuration_setcon_lm import SetConLMConfig # noqa: E402
39
+ from .processing_setcon import place_devices # noqa: E402
40
+
41
+ CE_CHUNK = 256 # answer positions per vocabulary projection when scoring candidates (as in training)
42
+
43
+
44
+ def _mlp(d_in, d_out):
45
+ return nn.Sequential(nn.Linear(d_in, d_out), nn.GELU(), nn.Linear(d_out, d_out))
46
+
47
+
48
+ class SetConProjector(nn.Module):
49
+ """Encoder features of one window -> LM input vectors: the setup token, then one token per worn site and valid
50
+ patch (sites in index order, patches in time order within each site)."""
51
+
52
+ def __init__(self, encoder_dim, lm_dim, num_sites, num_patches):
53
+ super().__init__()
54
+ self.setup_mlp = _mlp(encoder_dim, lm_dim)
55
+ self.patch_mlp = _mlp(encoder_dim, lm_dim)
56
+ self.site_embedding = nn.Embedding(num_sites, lm_dim)
57
+ self.time_embedding = nn.Embedding(num_patches, lm_dim)
58
+ self.token_type_embedding = nn.Embedding(2, lm_dim) # 0 = setup token, 1 = patch token
59
+ self.norm = nn.LayerNorm(lm_dim)
60
+ self.scale = nn.Parameter(torch.tensor(0.02))
61
+
62
+ def forward(self, setup, tokens, worn, patch_valid):
63
+ """setup (encoder_dim), tokens (sites, patches, encoder_dim), worn (sites) bool, patch_valid (patches) bool
64
+ -> (1 + worn sites x valid patches, lm_dim)."""
65
+ sites = torch.nonzero(worn, as_tuple=False).flatten()
66
+ patches = torch.nonzero(patch_valid, as_tuple=False).flatten()
67
+ first = self.setup_mlp(setup)[None] + self.token_type_embedding.weight[0][None]
68
+ x = self.patch_mlp(tokens[sites][:, patches]) + self.site_embedding(sites)[:, None] + \
69
+ self.time_embedding(patches)[None, :] + self.token_type_embedding.weight[1]
70
+ out = torch.cat([first, x.reshape(-1, x.shape[-1])], dim=0)
71
+ return self.norm(out) * self.scale
72
+
73
+
74
+ @torch.no_grad()
75
+ def encoder_tokens(setcon, x, worn, gyro, patch_valid):
76
+ """The frozen encoder's setup vector (B, 256) and patch tokens (B, 22, 50, 256; zero where no site is worn or a
77
+ patch is invalid), read from its own forward pass under bfloat16 autocast on CUDA, as float32."""
78
+ enc = setcon.encoder
79
+ got = {}
80
+ hooks = [enc.setup_embed.register_forward_hook(lambda m, i, o: got.__setitem__("setup", o)),
81
+ enc.final_norm.register_forward_hook(lambda m, i, o: got.__setitem__("tokens", o))]
82
+ try:
83
+ with torch.autocast("cuda", dtype=torch.bfloat16, enabled=x.is_cuda):
84
+ enc(x, worn, gyro, patch_valid)
85
+ finally:
86
+ for h in hooks:
87
+ h.remove()
88
+ observed = worn[:, :, None] & patch_valid[:, None, :]
89
+ return got["setup"].float(), got["tokens"].masked_fill(~observed[..., None], 0).float()
90
+
91
+
92
+ class SetConLM(PreTrainedModel):
93
+ """Projector + Qwen3.5-0.8B (fine-tuned). Use `ask` for free answers; `choose` and `yes_no` score given answers
94
+ by likelihood, the way the paper reads its candidate questions."""
95
+
96
+ config_class = SetConLMConfig
97
+ base_model_prefix = "setcon_lm"
98
+ main_input_name = "inputs_embeds"
99
+ _tied_weights_keys = {"lm.lm_head.weight": "lm.model.embed_tokens.weight"}
100
+
101
+ def __init__(self, config: SetConLMConfig):
102
+ super().__init__(config)
103
+ self.projector = SetConProjector(config.encoder_hidden_size, config.text_config.hidden_size, config.num_sites,
104
+ config.num_patches)
105
+ self.lm = Qwen3_5ForCausalLM(config.text_config)
106
+ self.tokenizer = None
107
+ self.post_init()
108
+
109
+ def _init_weights(self, module):
110
+ """Weights always come from a checkpoint."""
111
+
112
+ def get_input_embeddings(self):
113
+ return self.lm.get_input_embeddings()
114
+
115
+ @classmethod
116
+ def from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs):
117
+ """Also loads the tokenizer (with the chat template) stored next to the weights."""
118
+ model = super().from_pretrained(pretrained_model_name_or_path, *args, **kwargs)
119
+ hub = {k: kwargs[k] for k in ("subfolder", "revision", "cache_dir", "token", "local_files_only",
120
+ "force_download", "proxies") if kwargs.get(k) is not None}
121
+ model.tokenizer = Qwen2Tokenizer.from_pretrained(pretrained_model_name_or_path, **hub)
122
+ return model
123
+
124
+ # ---------------------------------------------------------------- inputs
125
+ def _check_encoder(self, setcon):
126
+ seed = getattr(setcon.config, "training_seed", None)
127
+ if seed != self.config.encoder_training_seed:
128
+ k = self.config.encoder_training_seed
129
+ raise ValueError(f"this language model was trained on SetCon seed {k}, the encoder given is seed {seed}; "
130
+ f"load the encoder with " + ("no subfolder" if k == 1 else f"subfolder='seed{k}'"))
131
+
132
+ @staticmethod
133
+ def encoder_inputs(setcon, windows):
134
+ """windows: (N, 200, 22, 9) or (200, 22, 9) model windows with the reference channels set, or
135
+ {site name: (N, 200, 9)} of devices worn together, or a tuple (x, worn, gyro, patch_valid) of prepared
136
+ encoder inputs as returned by SetConModel.encoder_inputs. Returns that tuple (CPU tensors)."""
137
+ if isinstance(windows, tuple) and len(windows) == 4 and np.ndim(windows[1]) == 2:
138
+ return tuple(torch.as_tensor(t) for t in windows)
139
+ if isinstance(windows, dict):
140
+ windows = place_devices(windows)
141
+ w = np.asarray(windows, dtype=np.float32)
142
+ if w.ndim == 3:
143
+ w = w[None]
144
+ return setcon.encoder_inputs(torch.from_numpy(np.ascontiguousarray(w)))
145
+
146
+ @torch.no_grad()
147
+ def prefixes(self, setcon, x, worn, gyro, patch_valid):
148
+ """LM input vectors of a batch of windows (one tensor per window, float32 on the LM's device)."""
149
+ dev = next(setcon.encoder.parameters()).device
150
+ x, worn, gyro, patch_valid = (t.to(dev) for t in (x, worn, gyro, patch_valid))
151
+ setup, tokens = encoder_tokens(setcon, x, worn, gyro, patch_valid)
152
+ lm_dev = self.device
153
+ setup, tokens, worn, patch_valid = (t.to(lm_dev) for t in (setup, tokens, worn, patch_valid))
154
+ with torch.autocast("cuda", dtype=torch.bfloat16, enabled=setup.is_cuda):
155
+ return [self.projector(setup[i], tokens[i], worn[i], patch_valid[i]) for i in range(len(setup))]
156
+
157
+ def worn_line(self, worn):
158
+ sites = [self.config.site_text[j] for j in np.flatnonzero(np.asarray(worn))]
159
+ return "Sensors worn at: " + ", ".join(sites) + "."
160
+
161
+ def prompt_ids(self, worn, question):
162
+ """Chat prompt token ids: system prompt, then the worn-site line and the question as the user turn."""
163
+ msgs = [{"role": "system", "content": self.config.system_prompt},
164
+ {"role": "user", "content": self.worn_line(worn) + "\n" + question}]
165
+ out = self.tokenizer.apply_chat_template(msgs, add_generation_prompt=True, tokenize=True,
166
+ enable_thinking=False)
167
+ if hasattr(out, "keys") and "input_ids" in out.keys():
168
+ out = out["input_ids"]
169
+ out = list(out)
170
+ if out and isinstance(out[0], (list, tuple)):
171
+ out = list(out[0])
172
+ return out
173
+
174
+ def _token_id(self, text):
175
+ return self.tokenizer.convert_tokens_to_ids(text)
176
+
177
+ def _questions(self, question, n):
178
+ q = self.config.default_question if question is None else question
179
+ q = [q] * n if isinstance(q, str) else list(q)
180
+ if len(q) != n:
181
+ raise ValueError(f"{len(q)} questions for {n} windows")
182
+ return q
183
+
184
+ # ---------------------------------------------------------------- free answers
185
+ @torch.no_grad()
186
+ def generate_answers(self, prefixes, prompts, max_new_tokens=None):
187
+ """Greedy answers for one batch: [prefix | prompt] left-padded. Returns dicts (text, token_ids, stopped)."""
188
+ max_new_tokens = max_new_tokens or self.config.max_new_tokens
189
+ embed = self.lm.get_input_embeddings()
190
+ dev = self.device
191
+ seqs = []
192
+ for k, pid in enumerate(prompts):
193
+ e = embed(torch.tensor(pid, device=dev))
194
+ seqs.append(e if prefixes is None else torch.cat([prefixes[k].to(e.dtype), e], 0))
195
+ L = max(s.shape[0] for s in seqs)
196
+ inp = torch.zeros(len(seqs), L, seqs[0].shape[-1], dtype=seqs[0].dtype, device=dev)
197
+ mask = torch.zeros(len(seqs), L, dtype=torch.long, device=dev)
198
+ for i, s in enumerate(seqs):
199
+ inp[i, L - s.shape[0]:] = s
200
+ mask[i, L - s.shape[0]:] = 1
201
+ stop = [self._token_id(t) for t in self.config.stop_tokens]
202
+ out = self.lm.generate(inputs_embeds=inp, attention_mask=mask, max_new_tokens=max_new_tokens,
203
+ do_sample=False, eos_token_id=stop, pad_token_id=self._token_id("<|endoftext|>"))
204
+ res = []
205
+ for r in out.tolist():
206
+ cut = next((j for j, t in enumerate(r) if t in stop), len(r))
207
+ res.append(dict(text=self.tokenizer.decode(r[:cut], skip_special_tokens=True).strip(),
208
+ token_ids=r[:cut + 1] if cut < len(r) else r, stopped=cut < len(r)))
209
+ return res
210
+
211
+ @torch.no_grad()
212
+ def ask(self, setcon, windows, question=None, batch_size=None, max_new_tokens=None, return_details=False):
213
+ """Free answer to `question` (one string for all windows, or one per window; default "What is the person
214
+ doing?") for every window. Returns a list of strings, or of dicts (text, token_ids, stopped)."""
215
+ self._check_encoder(setcon)
216
+ x, worn, gyro, pv = self.encoder_inputs(setcon, windows)
217
+ qs = self._questions(question, len(x))
218
+ bs = batch_size or self.config.batch_size
219
+ res = []
220
+ for lo in range(0, len(x), bs):
221
+ sl = slice(lo, min(len(x), lo + bs))
222
+ pres = self.prefixes(setcon, x[sl], worn[sl], gyro[sl], pv[sl])
223
+ pids = [self.prompt_ids(worn[i].numpy(), qs[i]) for i in range(sl.start, sl.stop)]
224
+ res += self.generate_answers(pres, pids, max_new_tokens)
225
+ return res if return_details else [r["text"] for r in res]
226
+
227
+ # ---------------------------------------------------------------- scoring given answers
228
+ @torch.no_grad()
229
+ def answer_nll(self, prefix, prompt, answers):
230
+ """Mean negative log-likelihood per token of each answer (its tokens + <|im_end|>) after [prefix | prompt]."""
231
+ embed = self.lm.get_input_embeddings()
232
+ dev = self.device
233
+ end_id = self._token_id("<|im_end|>")
234
+ seqs, labels = [], []
235
+ for ans in answers:
236
+ e = embed(torch.tensor(prompt, device=dev))
237
+ aid = torch.tensor(self.tokenizer(ans, add_special_tokens=False)["input_ids"] + [end_id], device=dev)
238
+ n_p = 0 if prefix is None else prefix.shape[0]
239
+ parts = ([] if prefix is None else [prefix.to(e.dtype)]) + [e, embed(aid)]
240
+ seqs.append(torch.cat(parts, 0))
241
+ labels.append(torch.cat([torch.full((n_p + e.shape[0],), -100, dtype=torch.long, device=dev), aid]))
242
+ L = max(s.shape[0] for s in seqs)
243
+ inp = torch.zeros(len(seqs), L, seqs[0].shape[-1], dtype=seqs[0].dtype, device=dev)
244
+ mask = torch.zeros(len(seqs), L, dtype=torch.long, device=dev)
245
+ lab = torch.full((len(seqs), L), -100, dtype=torch.long, device=dev)
246
+ for i, (s, l_) in enumerate(zip(seqs, labels)):
247
+ inp[i, :s.shape[0]] = s
248
+ mask[i, :s.shape[0]] = 1
249
+ lab[i, :l_.shape[0]] = l_
250
+ hs = self.lm.model(inputs_embeds=inp, attention_mask=mask).last_hidden_state
251
+ tgt = lab[:, 1:]
252
+ m = tgt != -100
253
+ hsel, tsel = hs[:, :-1][m], tgt[m]
254
+ ce = torch.cat([F.cross_entropy(self.lm.lm_head(hsel[c:c + CE_CHUNK]).float(), tsel[c:c + CE_CHUNK],
255
+ reduction="none") for c in range(0, hsel.shape[0], CE_CHUNK)])
256
+ full = torch.zeros(tgt.shape, dtype=ce.dtype, device=dev)
257
+ full[m] = ce
258
+ mf = m.float()
259
+ return ((full * mf).sum(1) / mf.sum(1).clamp(min=1.0)).cpu().tolist()
260
+
261
+ @torch.no_grad()
262
+ def choose(self, setcon, windows, question, candidates):
263
+ """Pick one of the candidate answers per window by the lowest mean token NLL (paper: the five-way questions
264
+ and the four-way activity choice). candidates: one list for all windows or one list per window.
265
+ Returns dicts (index, nll)."""
266
+ self._check_encoder(setcon)
267
+ x, worn, gyro, pv = self.encoder_inputs(setcon, windows)
268
+ qs = self._questions(question, len(x))
269
+ per_window = len(candidates) == len(x) and all(isinstance(c, (list, tuple)) for c in candidates)
270
+ res = []
271
+ for i in range(len(x)):
272
+ pre = self.prefixes(setcon, x[i:i + 1], worn[i:i + 1], gyro[i:i + 1], pv[i:i + 1])[0]
273
+ nll = self.answer_nll(pre, self.prompt_ids(worn[i].numpy(), qs[i]),
274
+ candidates[i] if per_window else candidates)
275
+ res.append(dict(index=int(np.argmin(nll)), nll=nll))
276
+ return res
277
+
278
+ @torch.no_grad()
279
+ def yes_no(self, setcon, windows, question):
280
+ """Yes/no question per window: log P("Yes") and log P("No") as the first answer token.
281
+ Returns dicts (answer 'yes' or 'no', log_p_yes, log_p_no)."""
282
+ self._check_encoder(setcon)
283
+ x, worn, gyro, pv = self.encoder_inputs(setcon, windows)
284
+ qs = self._questions(question, len(x))
285
+ yes = self.tokenizer("Yes", add_special_tokens=False)["input_ids"][0]
286
+ no = self.tokenizer("No", add_special_tokens=False)["input_ids"][0]
287
+ embed = self.lm.get_input_embeddings()
288
+ res = []
289
+ for i in range(len(x)):
290
+ pre = self.prefixes(setcon, x[i:i + 1], worn[i:i + 1], gyro[i:i + 1], pv[i:i + 1])[0]
291
+ e = embed(torch.tensor(self.prompt_ids(worn[i].numpy(), qs[i]), device=self.device))
292
+ inp = torch.cat([pre.to(e.dtype), e], 0)[None]
293
+ hs = self.lm.model(inputs_embeds=inp, attention_mask=torch.ones(1, inp.shape[1], dtype=torch.long,
294
+ device=self.device)).last_hidden_state
295
+ lp = F.log_softmax(self.lm.lm_head(hs[:, -1]).float(), -1)[0]
296
+ ly, ln = float(lp[yes]), float(lp[no])
297
+ res.append(dict(answer="yes" if ly > ln else "no", log_p_yes=ly, log_p_no=ln))
298
+ return res
requirements-lm.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Environment of the language model (lm/, examples/ask_lm.py). Qwen3.5 needs transformers 5, which needs
2
+ # Python >= 3.10; the encoder alone keeps requirements.txt. Reference environment of the paper's language-model
3
+ # answers: Python 3.12, NVIDIA H100 with CUDA 12.8 wheels, the versions below.
4
+ --extra-index-url https://download.pytorch.org/whl/cu128
5
+ torch==2.8.0+cu128
6
+ numpy==2.0.2
7
+ scipy==1.13.1
8
+ transformers==5.14.1
9
+ tokenizers==0.22.2
10
+ safetensors==0.8.0
11
+ huggingface_hub==1.22.0
12
+ # Kernels of the Gated DeltaNet layers (without them transformers falls back to a slower torch path, and single
13
+ # answers can change):
14
+ flash-linear-attention==0.5.2
15
+
16
+ # Install separately, after the lines above (causal-conv1d compiles against the installed torch; the reference
17
+ # environment had triton 3.7.1 installed over the triton 3.4.0 that torch 2.8.0 asks for, and pip warns about it):
18
+ # pip install --no-build-isolation causal-conv1d==1.7.0
19
+ # pip install triton==3.7.1