Skip to content

Commit e289aed

Browse files
author
daixu
committed
add model name
1 parent 420062b commit e289aed

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

configuration_llama.py

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def __init__(
155155
self._rope_scaling_validation()
156156
self.attention_bias = attention_bias
157157
self.weights_dir = weights_dir
158+
self.model_name = kwargs.pop("_name_or_path", None)
158159

159160
def _rope_scaling_validation(self):
160161
"""

naked_llama2.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def llama2(token_ids: torch.Tensor, config: LlamaConfig):
2929

3030
# 重复 32次(7B)/ 80次(70B) llama2_transformer_block 的计算
3131
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}')
3333
output = llama2_transformer_block(hidden_states, config, layer_id=layer_id, attention_mask=mask)
3434
hidden_states = output[0]
3535

@@ -87,15 +87,15 @@ def llama2(token_ids: torch.Tensor, config: LlamaConfig):
8787
config.weights_dir = model_dict[model_name]['weights_dir']
8888
logits = llama2(token_ids, config)
8989

90-
print('Naked llama result:')
90+
print(f'Naked llama, model: {config.model_name}, result:')
9191
print(logits)
9292

9393
# check result
9494
model = LlamaForCausalLM.from_pretrained(model_dict[model_name]['hf_model'])
9595
model.eval()
9696
with torch.inference_mode():
9797
hf_res = model(input_ids = token_ids)
98-
print('Hugging face llama result:')
98+
print(f'Hugging face, model: {config.model_name}, result:')
9999
print(hf_res.logits)
100100
error = torch.abs(hf_res.logits-logits)
101101
print(f"Compare error sum: {torch.sum(error)}")

0 commit comments

Comments
 (0)