Skip to content

Commit 9b4c92a

Browse files
committed
Refactor comments and clean code
1 parent 25e8431 commit 9b4c92a

21 files changed

+70
-59
lines changed

models/experimental/mistral_24b/tests/pipeline_tests/test_end2end.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-FileCopyrightText: © 2025 Tenstorrent Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
14
"""Test for Mistral-24B End-to-End Vision-Text Pipeline"""
25

36
import torch
@@ -157,7 +160,6 @@ def process_real_vision_inputs(messages, model_args):
157160
)
158161

159162
image_inputs, video_inputs = process_vision_info(messages)
160-
# image_inputs, video_inputs = None, None
161163

162164
encoded = processor(
163165
text=[text], images=image_inputs, videos=video_inputs, return_tensors="pt", return_dict=True
@@ -284,7 +286,7 @@ def run_generation_exactly_like_test_end2end(
284286

285287
topk_tokens = [model_args.tokenizer.decode([idx.item()]) for idx in topk_indices]
286288

287-
logger.info("🔍 Top-5 predicted tokens (with probabilities):")
289+
logger.info("Top-5 predicted tokens (with probabilities):")
288290
for i in range(top_k):
289291
logger.info(f"{i+1}. Token: '{topk_tokens[i]}' (ID={topk_indices[i].item()}), P={topk_probs[i].item():.4f}")
290292

@@ -347,17 +349,17 @@ def run_generation_exactly_like_test_end2end(
347349

348350
# Final response (exactly like test_end2end.py)
349351
response = model_args.tokenizer.decode(all_outputs[0], skip_special_tokens=True)
350-
logger.info(f"📝 Each iteration Generated Response:\n{response}")
351-
logger.info(f"📝 Each iteration Generated {len(all_outputs[0])} tokens: {all_outputs[0]}")
352+
logger.info(f"Each iteration Generated Response:\n{response}")
353+
logger.info(f"Each iteration Generated {len(all_outputs[0])} tokens: {all_outputs[0]}")
352354
chat = parse_chat_output(response)
353355
display_chat(logger, chat)
354356

355357
logger.info(f" Each iteration Generated {len(results)} tokens successfully")
356358

357359
# Final response (exactly like test_end2end.py)
358360
response = model_args.tokenizer.decode(all_outputs[0], skip_special_tokens=True)
359-
logger.info(f"📝 Final Generated Response:\n{response}")
360-
logger.info(f"📝 Generated {len(all_outputs[0])} tokens: {all_outputs[0]}")
361+
logger.info(f"Final Generated Response:\n{response}")
362+
logger.info(f"Generated {len(all_outputs[0])} tokens: {all_outputs[0]}")
361363
chat = parse_chat_output(response)
362364
display_chat(logger, chat)
363365

@@ -469,9 +471,6 @@ def test_e2e_vision_text_pipeline(
469471
# Setup vision prompts and tokenizer
470472
messages, tokenizer = setup_vision_prompts_and_tokenizer(model_args, instruct)
471473

472-
# logger.info("Running reference HF vision-text model using messages..... ")
473-
# hf_output = run_reference_demo_pipeline(messages)
474-
475474
# Process real vision inputs from images
476475
processed_inputs = process_real_vision_inputs(messages, model_args)
477476

@@ -524,12 +523,12 @@ def test_e2e_vision_text_pipeline(
524523

525524
# Final validation
526525
if validation_passed and len(results) > 0:
527-
logger.info("E2E vision-text pipeline test PASSED!")
526+
logger.info("E2E vision-text pipeline test PASSED!")
528527
logger.info(f"Successfully generated {len(results)} tokens")
529528

530529
# Log generated tokens for debugging
531530
for i, result in enumerate(results[:5]):
532531
logger.info(f"Token {i}: {result.token} -> '{result.text}'")
533532
else:
534-
logger.error("E2E pipeline test failed")
533+
logger.error("E2E pipeline test failed")
535534
assert False, f"E2E pipeline failed - generated {len(results)} tokens, validation: {validation_passed}"

models/experimental/mistral_24b/tests/pipeline_tests/test_vision_model.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.
1+
# SPDX-FileCopyrightText: © 2025 Tenstorrent Inc.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
"""
5+
This file is a unit test for validating the Mistral-24B Vision Model pipeline.
6+
"""
7+
48
import os
59
import pytest
610
import torch

models/experimental/mistral_24b/tests/pipeline_tests/test_vision_tower.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.
1+
# SPDX-FileCopyrightText: © 2025 Tenstorrent Inc.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
"""
5+
This file is a unit test for validating the Mistral-24B Vision Tower model.
6+
"""
7+
48
import os
59
import pytest
610
import torch

models/experimental/mistral_24b/tests/test_conv2d.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.
2-
1+
# SPDX-FileCopyrightText: © 2025 Tenstorrent Inc.
32
# SPDX-License-Identifier: Apache-2.0
43

4+
"""
5+
This file is a unit test for validating the Mistral-24B conv2d.
6+
"""
57
import os
68

79
import pytest

models/experimental/mistral_24b/tests/test_patch_rot_emb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
# SPDX-FileCopyrightText: © 2025 Tenstorrent Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
14
from loguru import logger
25

36
import torch
47
import pytest
58
import os
69
import ttnn
710

8-
# models/tt_transformers/tt/common.py
911
from models.experimental.mistral_24b.tt.vision_rope import VisionRotarySetup as RotarySetup
1012

1113
from models.utility_functions import comp_allclose, comp_pcc, skip_for_grayskull

models/experimental/mistral_24b/tests/test_pixtral_transformer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.
2-
1+
# SPDX-FileCopyrightText: © 2025 Tenstorrent Inc.
32
# SPDX-License-Identifier: Apache-2.0
3+
44
import os
55

66
import pytest

models/experimental/mistral_24b/tests/test_vision_attention.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.
2-
1+
# SPDX-FileCopyrightText: © 2025 Tenstorrent Inc.
32
# SPDX-License-Identifier: Apache-2.0
43

54
import os
@@ -81,11 +80,6 @@ def test_vision_attention(mesh_device, seq_len, batch_size):
8180
cos = torch.ones((1, T, head_dim)).to(torch.bfloat16)
8281
sin = torch.zeros((1, T, head_dim)).to(torch.bfloat16)
8382

84-
# attention_input = model_args.prepare_residual_tensor_prefill(
85-
# pt_attention_input,
86-
# force_replicated=True,
87-
# )
88-
8983
attention_input = ttnn.from_torch(
9084
pt_attention_input.unsqueeze(0),
9185
device=mesh_device,

models/experimental/mistral_24b/tests/test_vision_mlp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.
1+
# SPDX-FileCopyrightText: © 2025 Tenstorrent Inc.
22

33
# SPDX-License-Identifier: Apache-2.0
44

models/experimental/mistral_24b/tests/test_vision_rms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-FileCopyrightText: © 2025 Tenstorrent Inc.
2+
3+
# SPDX-License-Identifier: Apache-2.0
4+
15
from loguru import logger
26

37
import torch

models/experimental/mistral_24b/tt/model.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-FileCopyrightText: © 2025 Tenstorrent Inc.
2+
3+
# SPDX-License-Identifier: Apache-2.0
4+
15
"""
26
This is the end-to-end pipeline for the Mistral-Small-3.1-24B-Instruct-2503 model.
37
@@ -51,9 +55,7 @@ def prepare_inputs_prefill(self, tokens, start_pos=0, page_table=None, chunk_pag
5155
layout=ttnn.ROW_MAJOR_LAYOUT,
5256
mesh_mapper=ttnn.ReplicateTensorToMesh(self.mesh_device),
5357
)
54-
# self.embed_scale = args.dim**0.5
5558
tokens_embd = self.embd(tokens)
56-
# tokens_embd = ttnn.multiply(tokens_embd, self.embed_scale)
5759

5860
pixel_values = kwargs["processed_inputs"]["pixel_values"]
5961
input_ids = kwargs["processed_inputs"]["input_ids"]
@@ -73,7 +75,6 @@ def prepare_inputs_prefill(self, tokens, start_pos=0, page_table=None, chunk_pag
7375
input_ids = torch.nn.functional.pad(
7476
input_ids, (0, tokens_embd.shape[1] - input_ids.shape[1]), "constant", 0
7577
)
76-
# image_features = image_features.squeeze(0)
7778
special_image_mask = (input_ids == 10).unsqueeze(-1)
7879
special_image_mask = special_image_mask.expand_as(tokens_embd)
7980
image_features = image_features.to(tokens_embd.device, tokens_embd.dtype)

0 commit comments

Comments
 (0)