项目文件夹

文件
wehub-resource-sync 78ec5d9290
ci-cd / build-axolotl-uv (<nil>, 130, 13.0.0, linux/amd64,linux/arm64, 3.12, 2.11.0) (push) Has been cancelled
ci-cd / build-axolotl-uv (<nil>, 130, 13.0.0, true, linux/amd64,linux/arm64, 3.12, 2.12.0) (push) Has been cancelled
ci-cd / build-axolotl-cloud-uv (<nil>, 130, 13.0.0, linux/amd64,linux/arm64, 3.12, 2.11.0) (push) Has been cancelled
ci-cd / build-axolotl-cloud-uv (<nil>, 130, 13.0.0, true, linux/amd64,linux/arm64, 3.12, 2.12.0) (push) Has been cancelled
ci-cd / build-axolotl-cloud-no-tmux-uv (<nil>, 130, 13.0.0, linux/amd64,linux/arm64, 3.12, 2.11.0) (push) Has been cancelled
ci-cd / build-axolotl-cloud-no-tmux-uv (<nil>, 130, 13.0.0, true, linux/amd64,linux/arm64, 3.12, 2.12.0) (push) Has been cancelled
ci-cd-base / build-base-uv (130, 13.0.0, , Dockerfile-uv-base, linux/amd64,linux/arm64, 3.12, 2.12.0, 9.0 10.0 10.3 12.0+PTX) (push) Has been cancelled
ci-cd-base / build-base-uv (130, 13.0.0, , Dockerfile-uv-base, linux/amd64,linux/arm64, 3.12, 2.12.1, 9.0 10.0 10.3 12.0+PTX) (push) Has been cancelled
ci-cd-base / build-base-uv (130, 13.0.0, , Dockerfile-uv-base, linux/amd64,linux/arm64, 3.12, 2.13.0, 9.0 10.0 10.3 12.0+PTX) (push) Has been cancelled
ci-cd-base / build-base-uv (132, 13.2.1, , Dockerfile-uv-base, linux/amd64,linux/arm64, 3.12, 2.13.0, 9.0 10.0 10.3 12.0+PTX, https://download.pytorch.org/whl/cu132) (push) Has been cancelled
ci-cd-base / build-base-uv (130, 13.0.0, , Dockerfile-uv-base, linux/amd64,linux/arm64, 3.12, 2.11.0, 9.0 10.0 10.3 12.0+PTX) (push) Has been cancelled
Tests / PyTest (3.12, 2.12.1) (push) Has been cancelled
Tests / PyTest (3.12, 2.13.0) (push) Has been cancelled
docker-e2e-tests / gate-skip-e2e (push) Has been cancelled
docker-e2e-tests / docker-e2e-tests-1st (<nil>, 130, 13.0.0, 1, 3.12, 2.12.1) (push) Has been cancelled
docker-e2e-tests / docker-e2e-tests (<nil>, 130, 13.0.0, 1, 3.12, 2.11.0) (push) Has been cancelled
docker-e2e-tests / docker-e2e-kernel-tests (<nil>, 130, 13.0.0, 1, 3.12, 2.11.0) (push) Has been cancelled
docker-e2e-tests / docker-e2e-kernel-tests (<nil>, 130, 13.0.0, 1, 3.12, 2.12.1) (push) Has been cancelled
docker-e2e-tests / docker-e2e-cleanup (<nil>, 130, 13.0.0, 1, 3.12, 2.12.1) (push) Has been cancelled
Publish Docs / build-deploy (push) Has been cancelled
Tests / PyTest from Source Dist (3.12, 2.11.0) (push) Has been cancelled
Tests / PyTest from Source Dist (3.12, 2.12.1) (push) Has been cancelled
Tests / PyTest from Source Dist (3.12, 2.13.0) (push) Has been cancelled
Tests / pre-commit (push) Has been cancelled
Tests / Prefetch S3 once to prime the CDN cache (push) Has been cancelled
Tests / PyTest (3.12, 2.11.0) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:48:45 +08:00

150 行
4.9 KiB
Python

"""Tests for Mistral3Processor with transformers v5 ProcessorMixin integration"""
from unittest.mock import MagicMock
import pytest
import torch
from transformers.feature_extraction_utils import BatchFeature
from axolotl.utils.mistral.mistral3_processor import Mistral3Processor
from axolotl.utils.mistral.mistral_tokenizer import HFMistralTokenizer
@pytest.fixture()
def mock_tokenizer():
"""Create a mock HFMistralTokenizer that passes v5 ProcessorMixin isinstance checks."""
return MagicMock(spec=HFMistralTokenizer)
@pytest.fixture()
def processor(mock_tokenizer):
return Mistral3Processor(tokenizer=mock_tokenizer)
class TestMistral3ProcessorInit:
def test_tokenizer_is_set(self, processor, mock_tokenizer):
assert processor.tokenizer is mock_tokenizer
def test_chat_template_is_none(self, processor):
assert processor.chat_template is None
def test_audio_tokenizer_is_none(self, processor):
assert processor.audio_tokenizer is None
class TestApplyChatTemplateTokenized:
"""Test apply_chat_template with tokenize=True, return_dict=True"""
@pytest.fixture()
def batched_conversations(self):
return [
[
{"role": "user", "content": "Describe this image."},
{"role": "assistant", "content": "It is red."},
],
[
{"role": "user", "content": "What is this?"},
{"role": "assistant", "content": "A cat."},
],
]
def test_returns_batch_feature_with_pixel_values(
self, processor, mock_tokenizer, batched_conversations
):
pixel_values = torch.randn(2, 3, 224, 224, dtype=torch.float64)
mock_tokenizer.apply_chat_template.return_value = {
"input_ids": torch.tensor([[1, 2, 3], [4, 5, 6]]),
"attention_mask": torch.tensor([[1, 1, 1], [1, 1, 1]]),
"pixel_values": pixel_values,
}
result = processor.apply_chat_template(
batched_conversations, tokenize=True, return_dict=True
)
assert isinstance(result, BatchFeature)
assert "pixel_values" in result
assert "image_sizes" in result
assert result["pixel_values"].dtype == torch.float32
assert result["image_sizes"].shape == (2, 2)
assert result["image_sizes"][0].tolist() == [224, 224]
def test_returns_batch_feature_without_pixel_values(
self, processor, mock_tokenizer, batched_conversations
):
mock_tokenizer.apply_chat_template.return_value = {
"input_ids": torch.tensor([[1, 2, 3], [4, 5, 6]]),
"attention_mask": torch.tensor([[1, 1, 1], [1, 1, 1]]),
}
result = processor.apply_chat_template(
batched_conversations, tokenize=True, return_dict=True
)
assert isinstance(result, BatchFeature)
assert "input_ids" in result
assert "image_sizes" not in result
class TestApplyChatTemplateNotTokenized:
def test_single_conversation_returns_unwrapped(self, processor, mock_tokenizer):
"""Single conversation (not batched) should return unwrapped result."""
single_conversation = [
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hi"},
]
mock_tokenizer.apply_chat_template.return_value = [
"<s>[INST]Hello[/INST]Hi</s>"
]
result = processor.apply_chat_template(
single_conversation, tokenize=False, return_dict=False
)
assert result == "<s>[INST]Hello[/INST]Hi</s>"
def test_batched_conversations_returns_list(self, processor, mock_tokenizer):
batched = [
[
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hi"},
],
[
{"role": "user", "content": "Bye"},
{"role": "assistant", "content": "Bye"},
],
]
mock_tokenizer.apply_chat_template.return_value = ["text1", "text2"]
result = processor.apply_chat_template(
batched, tokenize=False, return_dict=False
)
assert result == ["text1", "text2"]
class TestCall:
def test_delegates_to_tokenizer(self, processor, mock_tokenizer):
mock_tokenizer.return_value = {
"input_ids": [1, 2, 3],
"attention_mask": [1, 1, 1],
}
result = processor("Hello world")
mock_tokenizer.assert_called_once()
assert isinstance(result, BatchFeature)
class TestReturnTensorsValidation:
def test_rejects_non_pt_return_tensors(self, processor):
conversation = [
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hi"},
]
with pytest.raises(ValueError, match=r"only supports.*return_tensors='pt'"):
processor.apply_chat_template(
conversation, tokenize=True, return_dict=True, return_tensors="np"
)