Sunshine-King commited on
Commit
5d0526d
Β·
verified Β·
1 Parent(s): a99e483

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +150 -0
  2. config.json +44 -0
README.md ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # HSTU 1B Generative Recommendation Model Test Configuration
2
+
3
+ [`config.json`](D:/tmp/hstu_1b/config.json) in this directory is the test configuration for the **HSTU** (Hierarchical Sequential Transduction Unit) generative recommendation model. This configuration describes the approximately **1B-parameter** HSTU test model and declares `HSTUForCausalLM` as its model entry point.
4
+
5
+ > **Note:** `use_random_model` is set to `true`. The model therefore uses randomly initialized weights for inference-pipeline, operator, and performance tests. This configuration does not indicate that a trained model checkpoint has been loaded.
6
+
7
+ ## 1. Configuration Summary
8
+
9
+ | Configuration | Value | Description |
10
+ | --- | ---: | --- |
11
+ | `model_type` | `hstu` | HSTU model type |
12
+ | `architectures` | `HSTUForCausalLM` | Model loading entry point. `CausalLM` is a framework-compatible interface name; the actual task is recommendation candidate scoring. |
13
+ | Intended model size | Approximately `1B` | Target size of the test model represented by this configuration |
14
+ | `num_hidden_layers` / `hstu_config.num_layers` | `12` | Number of HSTU layers |
15
+ | `hidden_size` | `4096` | Hidden-state dimension at each token or feature position |
16
+ | `num_attention_heads` | `16` | Number of attention heads per layer |
17
+ | `head_dim` | `256` | Dimension of each attention head; `16 Γ— 256 = 4096` |
18
+ | `max_seq_len` | `8832` | Maximum sequence length allowed for one request. The exact number of history and candidate positions depends on the input-packing scheme. |
19
+ | `torch_dtype` / `hstu_config.dtype` | `float32` | Data type used by this test configuration |
20
+ | `is_causal` | `true` | Enables causal masking, so a position cannot read future positions |
21
+ | `residual` | `true` | Enables residual connections in HSTU layers |
22
+ | `has_ffn` | `false` | No separate feed-forward network is included in each HSTU layer |
23
+ | `dropout_ratio` | `0` | Dropout is disabled for inference |
24
+ | `norm_epsilon` | `1e-5` | Numerical-stability epsilon used by normalization layers |
25
+
26
+ ## 2. Input Features and Embedding Tables
27
+
28
+ `task_config.embedding_configs` defines the recommendation features used by the model:
29
+
30
+ | Feature | Table | Vocabulary Size | Embedding Dimension | Dynamic Embedding | Purpose |
31
+ | --- | --- | ---: | ---: | --- | --- |
32
+ | `action_weights` | `act` | `1024` | `4096` | No | User behavior/action type or behavior weight |
33
+ | `video_id` | `item` | `100000` | `4096` | Yes | Video/item ID used as a candidate-item feature |
34
+
35
+ The configuration also declares:
36
+
37
+ - `item_feature_name = "video_id"`
38
+ - `action_feature_name = "action_weights"`
39
+ - Both input embedding dimensions match `hidden_size = 4096`.
40
+
41
+ In a typical HSTU inference implementation, input features first go through embedding lookup. Multiple features at the same position are combined through concatenation and/or a linear projection to form a 4096-dimensional input representation. Positional information is then added before the representation is passed to the HSTU backbone.
42
+
43
+ ## 3. HSTU Model Architecture
44
+
45
+ The logical path from model inputs to recommendation scores is:
46
+
47
+ ```text
48
+ User-history features + candidate-item features
49
+ β”‚
50
+ β”œβ”€ action_weights embedding: 4096 β†’ 4096
51
+ └─ video_id embedding: 4096 β†’ 4096
52
+ β”‚
53
+ └─ Feature combination / linear projection + positional embedding
54
+ β”‚
55
+ β–Ό
56
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
57
+ β”‚ HSTU Layer 1 β”‚
58
+ β”‚ … β”‚
59
+ β”‚ HSTU Layer 12 β”‚
60
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
61
+ β”‚
62
+ β–Ό
63
+ Hidden states at candidate positions
64
+ β”‚
65
+ β–Ό
66
+ Dense/MLP score head
67
+ β”‚
68
+ β–Ό
69
+ One scalar score for each candidate
70
+ ```
71
+
72
+ A single HSTU layer can be summarized as follows:
73
+
74
+ ```text
75
+ Input x
76
+ β”‚
77
+ β”œβ”€ Input normalization (epsilon = 1e-5)
78
+ β”œβ”€ Fused UVQK linear projection
79
+ β”‚ └─ Split into U, V, Q, and K representations
80
+ β”œβ”€ SiLU activation
81
+ β”œβ”€ Causal attention (16 heads, head_dim = 256)
82
+ β”œβ”€ Attention-output normalization
83
+ β”œβ”€ U gating / element-wise modulation of the attention output
84
+ β”œβ”€ Linear projection back to 4096 dimensions
85
+ └─ Residual connection (residual = true)
86
+ β”‚
87
+ Output x'
88
+ ```
89
+
90
+ Because `has_ffn = false`, this 1B configuration does **not** add a separate SwiGLU or other feed-forward sub-layer after the HSTU attention projection. The residual path is still enabled. The core per-layer transformation is therefore the normalized UVQK projection, causal attention, U-gated attention output, output projection, and residual addition.
91
+
92
+ This is not a conventional language model that generates text tokens. It uses a `ForCausalLM`-style interface to apply causal sequence modeling to the joint representation of user behavior history and candidate items, and ultimately produces a ranking score for each candidate. The current `config.json` does not explicitly specify the intermediate architecture of the prediction head under `task_config`; the concrete head configuration is determined by the model implementation or loader defaults. Its task semantics are to output one score per candidate.
93
+
94
+ ## 4. Inference Paradigm: Generative Recommendation vs. LLM
95
+
96
+ Both model types may expose a `CausalLM`-style interface, but their decode-stage objectives are fundamentally different.
97
+
98
+ ### 4.1 Generative Recommendation: Parallel Candidate Scoring
99
+
100
+ Given user history \(h\) and a candidate set \(C = \{c_1, \ldots, c_M\}\), HSTU computes a score for every candidate:
101
+
102
+ \[
103
+ s_i = f_\theta(h, c_i), \qquad i = 1, \ldots, M
104
+ \]
105
+
106
+ During decode, multiple candidates are arranged as positions or packed sequences that can be evaluated in parallel. A forward pass produces the score vector:
107
+
108
+ \[
109
+ \mathbf{s} = [s_1, s_2, \ldots, s_M]
110
+ \]
111
+
112
+ The candidates are then sorted by score and truncated to Top-K. Thus, the primary parallel dimension during decode is the **candidate dimension**. As the candidate count grows, candidate batching, candidate parallelism, and memory usage become important. The model does not need to generate \(c_1\) first and then generate \(c_2\) conditioned on \(c_1\).
113
+
114
+ ### 4.2 LLM: Autoregressive Token-by-Token Generation
115
+
116
+ Given a prompt prefix \(x_{<t}\), an LLM computes the distribution of the next token at step \(t\):
117
+
118
+ \[
119
+ p(x_t \mid x_{<t}) = \operatorname{softmax}(W h_t)
120
+ \]
121
+
122
+ After selecting or sampling a token, the token is appended to the sequence and the model proceeds to step \(t+1\), continuing until a complete sequence is generated or an EOS token is reached. The logits for the whole vocabulary can be computed in parallel at each step, but the **time dimension remains autoregressive and sequential**. The KV cache is primarily used to reuse the already generated prefix states.
123
+
124
+ ### 4.3 Comparison
125
+
126
+ | Dimension | HSTU Generative Recommendation | Conventional LLM |
127
+ | --- | --- | --- |
128
+ | Decode objective | Evaluate a set of candidate items simultaneously | Generate the next token |
129
+ | Computation unit | Candidate / candidate position | Token / time step |
130
+ | Typical output | `M` candidate scores, followed by sorting and Top-K selection | One token per step, repeated to form a complete sequence |
131
+ | Dependency pattern | Candidates generally do not require autoregressive dependencies on one another | The current token depends on previously generated tokens |
132
+ | Main parallel dimension | Candidate dimension; candidates can be batched and evaluated in parallel | Vocabulary logits are parallel within a step, but time steps are sequential |
133
+ | Stopping condition | Candidate scoring completes, followed by ranking/truncation | EOS, maximum generation length, or another stopping rule |
134
+ | Cache purpose | Reuse the user-history representation to reduce candidate-scoring cost | Reuse historical token K/V states to reduce incremental-generation cost |
135
+
136
+ In simplified form:
137
+
138
+ ```text
139
+ HSTU decode: history + [candidate_1 ... candidate_M]
140
+ └──────── one parallel forward pass β”€β”€β”€β”€β”€β”€β”€β”€β”˜
141
+ β†’ [score_1 ... score_M] β†’ Top-K
142
+
143
+ LLM decode: prompt β†’ token_1 β†’ token_2 β†’ … β†’ token_T
144
+ Each step determines or samples only the next token
145
+ ```
146
+
147
+ ## 5. Configuration Consistency Check
148
+
149
+ The top-level `vocab_size` is `1,001,024`, while the two explicitly configured embedding-table vocabulary sizes sum to `1024 + 100000 = 101,024`. If `vocab_size` represents the actual number of rows in a merged embedding table, verify whether the additional 900,000 IDs correspond to reserved IDs, dynamic-embedding capacity, or another offset. If they have no additional purpose, this field should be checked before loading real weights and tokenizer/ID mappings to avoid embedding out-of-range errors or unnecessary memory allocation.
150
+
config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "hstu",
3
+ "architectures": [
4
+ "HSTUForCausalLM"
5
+ ],
6
+ "num_hidden_layers": 12,
7
+ "use_random_model": true,
8
+ "max_seq_len": 8832,
9
+ "hidden_size": 4096,
10
+ "vocab_size": 1001024,
11
+ "torch_dtype": "float32",
12
+ "hstu_config": {
13
+ "hidden_size": 4096,
14
+ "num_layers": 12,
15
+ "num_attention_heads": 16,
16
+ "head_dim": 256,
17
+ "norm_epsilon": 1e-05,
18
+ "dtype": "float32",
19
+ "residual": true,
20
+ "is_causal": true,
21
+ "has_ffn": false,
22
+ "dropout_ratio": 0
23
+ },
24
+ "task_config": {
25
+ "embedding_configs": [
26
+ {
27
+ "feature_names": ["action_weights"],
28
+ "table_name": "act",
29
+ "vocab_size": 1024,
30
+ "dim": 4096,
31
+ "use_dynamicemb": false
32
+ },
33
+ {
34
+ "feature_names": ["video_id"],
35
+ "table_name": "item",
36
+ "vocab_size": 100000,
37
+ "dim": 4096,
38
+ "use_dynamicemb": true
39
+ }
40
+ ]
41
+ },
42
+ "item_feature_name": "video_id",
43
+ "action_feature_name": "action_weights"
44
+ }