@@ -29,7 +29,7 @@ def llama2(token_ids: torch.Tensor, config: LlamaConfig):
29
29
30
30
# 重复 32次(7B)/ 80次(70B) llama2_transformer_block 的计算
31
31
for layer_id in range (config .num_hidden_layers ):
32
- print (f'Naked llama: Computing Layer { layer_id } ' )
32
+ print (f'Naked llama: Computing { config . model_name } Layer { layer_id } ' )
33
33
output = llama2_transformer_block (hidden_states , config , layer_id = layer_id , attention_mask = mask )
34
34
hidden_states = output [0 ]
35
35
@@ -87,15 +87,15 @@ def llama2(token_ids: torch.Tensor, config: LlamaConfig):
87
87
config .weights_dir = model_dict [model_name ]['weights_dir' ]
88
88
logits = llama2 (token_ids , config )
89
89
90
- print ('Naked llama result:' )
90
+ print (f 'Naked llama, model: { config . model_name } , result:' )
91
91
print (logits )
92
92
93
93
# check result
94
94
model = LlamaForCausalLM .from_pretrained (model_dict [model_name ]['hf_model' ])
95
95
model .eval ()
96
96
with torch .inference_mode ():
97
97
hf_res = model (input_ids = token_ids )
98
- print ('Hugging face llama result:' )
98
+ print (f 'Hugging face, model: { config . model_name } , result:' )
99
99
print (hf_res .logits )
100
100
error = torch .abs (hf_res .logits - logits )
101
101
print (f"Compare error sum: { torch .sum (error )} " )
0 commit comments