Compare commits

..

1 Commits

Author SHA1 Message Date
Colin 7cf19b15cf Add image dump of query matmul key 2024-01-19 16:32:38 +08:00
244 changed files with 572570 additions and 8066 deletions

11
.gitignore vendored
View File

@ -1,12 +1,3 @@
__pycache__ __pycache__
.vscode .vscode
*.txt
*.npy
temp
lightning_logs
checkpoints
build
log
logs
data

88
chatglm/graph.md Normal file
View File

@ -0,0 +1,88 @@
## data flow
```
query -> "你好"
tokenizer -> input_ids [6]
rotary_pos_emb embedding -> [1, 6, 4096]
GLMBlock x 28 -> [6, 1, 4096] <━━━┓
RMSNorm -> [6, 1, 4096] ┃ final_layernorm
[-1:] -> [1, 1, 4096] ┃
Linear -> [1, 1, 65024] ┃ output_layer 4096->65024
softmax -> [1, 65024] ┃
multinomial -> [1] ┃
cat([input_ids, next_tokens]) ━━━┛
tokenizer.decode( )
# GLMBlock
input
RMSNorm hidden_states -> [6, 1, 4096]
┃ ┋
┃ ┋ ┃ pow(2) -> [6, 1, 4096]
┃ ┋ ┃ ┃
┃ ┋ ┃ mean -> [6, 1, 1]
┃ ┋ ┃ ↓
┃ ┋ ┃ rsqrt( + eps) -> [6, 1, 1]
┃ ┋ ╲
┃ ┋ mul -> [6, 1, 4096]
┃ ┋ ╲ weight -> [4096]
┃ ┋ ╲
┃ RMSNorm mul -> [6, 1, 4096]
┃ ╲
┃ SelfAttention x -> [6, 1, 4096]
┃ ┋ ┃
┃ ┋ Linear -> [6, 1, 4608] 4096->4608
┃ ┋ ┃ ╲
┃ ┋ q k v [6, 1, 32, 128] [6, 1, 2, 128] [6, 1, 2, 128]
┃ ┋ ┃ ╲
┃ ┋ pos_emb pos_emb ╲ -> cat( x0*y0-x1*y1, x1*y0-x0*y1, x, y)
┃ ┋ ┃ ┃ ┃
┃ ┋ ┃ expand expand -> [6, 1, 32, 128] [6, 1, 32, 128]
┃ ┋ permute permute permute -> [1, 32, 6, 128] [1, 32, 6, 128] [1, 32, 6, 128]
┃ ┋ ╲
┃ ┋ ┏---- matmul ┃ -> [1, 32, 6, 128] [1, 32, 128, 6] -> [1, 32, 6, 6]
┃ ┋ ┃ add(mask) -> [1, 32, 6, 6]
┃ ┋ attention┃ softmax -> [1, 32, 6, 6] dim:-1
┃ ┋ ┃ ╲
┃ ┋ ┗---- matmul -> [1, 32, 6, 6] [1, 32, 6, 128] -> [1, 32, 6, 128] -> [6, 1, 4096]
┃ SelfAttention Linear -> [6, 1, 4096] 4096->4096
┃ dropout
Add
┃ RMSNorm hidden_states -> [6, 1, 4096]
┃ ┋
┃ ┋ ┃ pow(2) -> [6, 1, 4096]
┃ ┋ ┃ ┃
┃ ┋ ┃ mean -> [6, 1, 1]
┃ ┋ ┃ ↓
┃ ┋ ┃ rsqrt( + eps) -> [6, 1, 1]
┃ ┋ ╲
┃ ┋ mul -> [6, 1, 4096]
┃ ┋ ╲ weight -> [4096]
┃ ┋ ╲
┃ RMSNorm mul -> [6, 1, 4096]
┃ mlp
┃ ┋ Linear -> [6, 1, 27392] 4096->27392
┃ ┋
┃ ┋ chunk1 chunk0 -> [6, 1, 13696]
┃ ┋ ┃ ┃ ╲
┃ ┋ ┃ ┃ sigmoid
┃ ┋ ┃ ┃
┃ ┋ ┃ mul
┃ ┋ ╲
┃ ┋ mul -> [6, 1, 13696]
┃ mlp Linear -> [6, 1, 4096] 13696->4096
┃ dropout
Add
```

View File

@ -0,0 +1,42 @@
# q matmul k
## model
qwen/Qwen-1_8B-Chat
## input
```python
<|im_start|>system
You are a helpful assistant.<|im_end|>
<|im_start|>user
你好<|im_end|>
<|im_start|>assistant
莎是现代汉语的男性的名字,出自《诗经》中的“采采卷耳
```
![](q_matmul_k_layer_0.png "")
![](q_matmul_k_layer_1.png "")
![](q_matmul_k_layer_2.png "")
![](q_matmul_k_layer_3.png "")
![](q_matmul_k_layer_4.png "")
![](q_matmul_k_layer_5.png "")
![](q_matmul_k_layer_6.png "")
![](q_matmul_k_layer_7.png "")
![](q_matmul_k_layer_8.png "")
![](q_matmul_k_layer_9.png "")
![](q_matmul_k_layer_10.png "")
![](q_matmul_k_layer_11.png "")
![](q_matmul_k_layer_12.png "")
![](q_matmul_k_layer_13.png "")
![](q_matmul_k_layer_14.png "")
![](q_matmul_k_layer_15.png "")
![](q_matmul_k_layer_16.png "")
![](q_matmul_k_layer_17.png "")
![](q_matmul_k_layer_18.png "")
![](q_matmul_k_layer_19.png "")
![](q_matmul_k_layer_20.png "")
![](q_matmul_k_layer_21.png "")
![](q_matmul_k_layer_22.png "")
![](q_matmul_k_layer_23.png "")

View File

@ -0,0 +1,67 @@
当前状态:
1.情绪: 狼狈不堪。
2.注意力: 检查自己的左手臂和膝盖是否有红肿或擦痕。
3.当前在思考什么: 应该及时处理伤口,免得后患无穷。也许回家再处理会更明智一点。
4.生理状态: 左手臂和膝盖疼痛不已,可能摔下有伤。
发现新情况: 发现膝盖流血了
请按照下面()里面回答我的问题,尽量得详细描述每一项,不要给其他的建议
1.情绪:()
2.注意力()
3.当前在思考什么()
4.生理状态()
当前状态:
情绪: 狼狈不堪。你感到困惑、不安和不舒服,可能还有一些惊恐或焦虑的情绪。这是因为你的身体受伤并且发现膝盖流血,这种情况会引起担忧和紧张情绪。
注意力: 你的注意力仍然集中在检查自己的左手臂和膝盖是否有红肿或擦痕上。你关注的重点是身体的伤势和状况,以及现在又出现了膝盖流血的情况,这进一步引起了你对伤势的关注和紧张。
当前在思考什么: 你正在思考应该如何及时处理伤口,以免留下后患。你之前考虑过回家再处理伤口,但现在面对膝盖流血的情况,你可能会重新评估并考虑寻求更及时的医疗帮助。你可能在思考是否需要立即就医或寻求其他形式的紧急救助。
生理状态: 你的左手臂和膝盖疼痛不已,这表明可能发生了摔倒或其他伤害。这种持续的疼痛会对你的日常活动和舒适感造成影响,并进一步增加了你的焦虑和不适感。此外,你现在还发现膝盖流血,这需要特别关注和处理。
发现新情况: 有一辆救护车过来了
请按照下面()里面回答我的问题,尽量得详细描述每一项,不要给其他的建议
1.情绪:()
2.注意力()
3.当前在思考什么()
4.生理状态()
当前状态:
情绪: 狼狈不堪。你的情绪可能有些紧张和不安,但同时也有一丝希望和宽慰,因为有一辆救护车过来了,这意味着有专业的医护人员将会提供帮助。
注意力: 你的注意力现在可能转移到了救护车的到来上。你可能在观察救护车的行动并期待医护人员的到来,以便能够得到适当的医疗和救助。
当前在思考什么: 你正在思考救护车的到来是否能够及时帮助你处理伤口。你可能在考虑接下来的行动,如如何与医护人员沟通、告知他们你的伤势情况以及对伤口的处理需求等。
生理状态: 你的左手臂和膝盖仍然疼痛,但现在有救护车的到来,你可以期待专业医护人员对你的伤势进行评估和处理。膝盖的出血也需要专业处理,救护车的到来为你提供了及时的医疗资源。
发现新情况: 救护车开走了
请按照下面()里面回答我的问题,尽量得详细描述每一项,不要给其他的建议
1.情绪:()
2.注意力()
3.当前在思考什么()
4.生理状态()
当前状态:
情绪: 你可能感到失望、焦虑和困惑,因为救护车开走了,没有提供及时的医疗帮助。你可能感到担心自己的伤势没有得到妥善处理,这可能增加了你的不安情绪。
注意力: 你的注意力可能再次转回到自己的伤势上,因为救护车离开了,你需要重新考虑接下来的行动。你可能在思考是否需要寻求其他的医疗资源或者联系其他人寻求帮助。
当前在思考什么: 你正在思考应该采取什么措施来处理伤口和缓解疼痛。你可能会考虑联系其他的医疗机构或者寻求朋友、家人的建议和支持。你也可能在思考如何前往医疗机构或医院寻求进一步的治疗。
生理状态: 你的左手臂和膝盖仍然疼痛,而且现在没有专业的医护人员提供帮助。你可能需要寻找其他方法来处理伤口和控制疼痛。你可以使用清洁的纱布或绷带暂时包扎伤口,并尽量避免过度活动,以免加重伤势。
发现新情况: 发现休息一会儿后,膝盖不疼了,而且可以走路了
请按照下面()里面回答我的问题,尽量得详细描述每一项,只要回答下面几项,不要给其他的建议
1.情绪:()
2.注意力()
3.当前在思考什么()
4.生理状态()
当前状态:
情绪: 你可能感到一些松了一口气,因为休息一会儿后,膝盖的疼痛减轻了,你能够走路了。你可能还感到一些困惑,因为之前的疼痛情况可能与你的预期不符。你可能会感到一些轻微的希望和安慰,因为你的伤势表现出一些好转的迹象。
注意力: 你的注意力可能会再次转移到你的身体感受上,因为你意识到膝盖的疼痛有所减轻,你能够走路了。你可能会开始思考接下来的行动,如是否需要进一步的医疗评估,或者是否可以自行处理伤口。
当前在思考什么: 你正在思考如何进一步处理伤口和控制疼痛。考虑到你能够走路了,你可能会思考是否仍然需要寻求医疗资源,或者是否可以采取自我护理措施来处理伤口。你可能会考虑使用适当的药物或采取其他方法来缓解疼痛和促进伤口的康复。
生理状态: 你的左手臂仍然疼痛,但你的膝盖疼痛减轻,并且你能够走路了。尽管如此,你的伤口仍然需要得到妥善处理和护理。你可以继续使用清洁的纱布或绷带来包扎伤口,以保持伤口的清洁和干燥。此外,继续避免过度活动是很重要的,以免加重伤势或引发其他并发症。
发现新情况: 肚子很饿
请按照下面()里面回答我的问题,尽量得详细描述每一项,只要回答下面几项,不要给其他的建议
1.情绪:()
2.注意力()
3.当前在思考什么()
4.生理状态()
情绪: 你可能感到一些松了一口气,因为伤口的疼痛有所减轻,你能够走路了。然而,由于你肚子很饿,你可能会感到一些不舒服和分散注意力的情绪。你可能会希望尽快解决饥饿问题,以恢复体力和精神状态。
注意力: 你的注意力可能会转移到你的饥饿感上,因为它变得非常强烈。你可能会开始思考如何解决肚子饿的问题,可能会考虑吃些东西来满足身体的需求。这可能会分散你对伤口处理和疼痛管理的注意力。
当前在思考什么: 你正在思考如何满足饥饿感和解决肚子饿的问题。你可能会思考是否有食物可用,以及如何获取食物。同时,你可能也会思考如何平衡满足饥饿感和继续处理伤口的需要。
生理状态: 你的左手臂仍然疼痛,但膝盖疼痛减轻,并且你能够走路了。然而,你现在感到非常饥饿,这可能对你的体力和精神状态产生影响。为了满足饥饿感,你可以尝试找到食物来满足身体的能量需求,并确保继续给伤口提供适当的护理。

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Some files were not shown because too many files have changed in this diff Show More