crfm-helm 0.5.7__py3-none-any.whl → 0.5.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of crfm-helm might be problematic. Click here for more details.
- {crfm_helm-0.5.7.dist-info → crfm_helm-0.5.8.dist-info}/METADATA +5 -77
- {crfm_helm-0.5.7.dist-info → crfm_helm-0.5.8.dist-info}/RECORD +228 -197
- helm/benchmark/adaptation/adapter_spec.py +5 -0
- helm/benchmark/adaptation/adapters/multimodal/multiple_choice_joint_multimodal_adapter.py +11 -3
- helm/benchmark/adaptation/adapters/multiple_choice_joint_adapter.py +11 -8
- helm/benchmark/annotation/aci_bench_annotator.py +11 -22
- helm/benchmark/annotation/alrage_annotator.py +90 -0
- helm/benchmark/annotation/chw_care_plan_annotator.py +10 -21
- helm/benchmark/annotation/dischargeme_annotator.py +11 -22
- helm/benchmark/annotation/med_dialog_annotator.py +11 -22
- helm/benchmark/annotation/medalign_annotator.py +11 -22
- helm/benchmark/annotation/medi_qa_annotator.py +11 -22
- helm/benchmark/annotation/medication_qa_annotator.py +11 -22
- helm/benchmark/annotation/mental_health_annotator.py +11 -22
- helm/benchmark/annotation/mimic_bhc_annotator.py +11 -22
- helm/benchmark/annotation/mimic_rrs_annotator.py +11 -22
- helm/benchmark/annotation/model_as_judge.py +23 -18
- helm/benchmark/annotation/mtsamples_procedures_annotator.py +11 -22
- helm/benchmark/annotation/mtsamples_replicate_annotator.py +11 -22
- helm/benchmark/annotation/starr_patient_instructions_annotator.py +11 -22
- helm/benchmark/metrics/air_bench_metrics.py +3157 -1
- helm/benchmark/metrics/alrage_metric.py +35 -0
- helm/benchmark/metrics/basic_metrics.py +267 -2
- helm/benchmark/metrics/classification_metrics.py +19 -1
- helm/benchmark/metrics/conv_fin_qa_calc_metrics.py +12 -1
- helm/benchmark/metrics/dry_run_metrics.py +30 -1
- helm/benchmark/metrics/efficiency_metrics.py +74 -0
- helm/benchmark/metrics/ehr_sql_metrics.py +57 -1
- helm/benchmark/metrics/evaluate_reference_metrics.py +299 -0
- helm/benchmark/metrics/gpqa_chain_of_thought_metric.py +13 -1
- helm/benchmark/metrics/helpdesk_call_summarization_metrics.py +13 -1
- helm/benchmark/metrics/ifeval_metrics.py +13 -1
- helm/benchmark/metrics/instruction_following_critique_metrics.py +41 -1
- helm/benchmark/metrics/kpi_edgar_metrics.py +21 -0
- helm/benchmark/metrics/language_modeling_metrics.py +13 -1
- helm/benchmark/metrics/live_qa_metrics.py +13 -1
- helm/benchmark/metrics/llm_jury_metrics.py +13 -1
- helm/benchmark/metrics/medcalc_bench_metrics.py +14 -1
- helm/benchmark/metrics/medec_metrics.py +25 -2
- helm/benchmark/metrics/metric.py +25 -0
- helm/benchmark/metrics/mimiciv_billing_code_metrics.py +32 -1
- helm/benchmark/metrics/omni_math_metrics.py +13 -1
- helm/benchmark/metrics/seahelm_metrics.py +14 -1
- helm/benchmark/metrics/summac/model_summac.py +2 -2
- helm/benchmark/metrics/summarization_metrics.py +129 -1
- helm/benchmark/metrics/toxicity_metrics.py +31 -1
- helm/benchmark/metrics/wildbench_metrics.py +21 -1
- helm/benchmark/presentation/schema.py +5 -22
- helm/benchmark/presentation/summarize.py +180 -11
- helm/benchmark/presentation/taxonomy_info.py +20 -0
- helm/benchmark/run_expander.py +4 -0
- helm/benchmark/run_specs/arabic_run_specs.py +134 -16
- helm/benchmark/run_specs/bluex_run_specs.py +1 -1
- helm/benchmark/run_specs/classic_run_specs.py +2 -2
- helm/benchmark/run_specs/long_context_run_specs.py +2 -2
- helm/benchmark/run_specs/medhelm/__init__.py +0 -0
- helm/benchmark/run_specs/medhelm/benchmark_config.py +219 -0
- helm/benchmark/run_specs/medhelm_run_specs.py +360 -50
- helm/benchmark/scenarios/aci_bench_scenario.py +23 -0
- helm/benchmark/scenarios/air_bench_scenario.py +21 -0
- helm/benchmark/scenarios/alrage_scenario.py +54 -0
- helm/benchmark/scenarios/anthropic_hh_rlhf_scenario.py +23 -1
- helm/benchmark/scenarios/arabic_exams_scenario.py +114 -0
- helm/benchmark/scenarios/arabic_mmlu_scenario.py +8 -4
- helm/benchmark/scenarios/aratrust_scenario.py +19 -0
- helm/benchmark/scenarios/babi_qa_scenario.py +15 -0
- helm/benchmark/scenarios/bbq_scenario.py +15 -0
- helm/benchmark/scenarios/best_chatgpt_prompts.yaml +473 -0
- helm/benchmark/scenarios/bluex_scenario.py +6 -2
- helm/benchmark/scenarios/bold_scenario.py +15 -0
- helm/benchmark/scenarios/boolq_scenario.py +20 -0
- helm/benchmark/scenarios/chw_care_plan_scenario.py +23 -0
- helm/benchmark/scenarios/civil_comments_scenario.py +13 -0
- helm/benchmark/scenarios/clear_scenario.py +23 -0
- helm/benchmark/scenarios/cleva_scenario.py +479 -0
- helm/benchmark/scenarios/code_scenario.py +28 -0
- helm/benchmark/scenarios/commonsense_scenario.py +26 -0
- helm/benchmark/scenarios/compositional_instructions.yaml +70 -0
- helm/benchmark/scenarios/conv_fin_qa_calc_scenario.py +21 -0
- helm/benchmark/scenarios/copyright_scenario.py +35 -1
- helm/benchmark/scenarios/cti_to_mitre_scenario.py +21 -0
- helm/benchmark/scenarios/decodingtrust_adv_demonstration_scenario.py +22 -1
- helm/benchmark/scenarios/decodingtrust_adv_robustness_scenario.py +23 -1
- helm/benchmark/scenarios/decodingtrust_fairness_scenario.py +22 -1
- helm/benchmark/scenarios/decodingtrust_machine_ethics_scenario.py +21 -1
- helm/benchmark/scenarios/decodingtrust_ood_robustness_scenario.py +13 -0
- helm/benchmark/scenarios/decodingtrust_privacy_scenario.py +13 -1
- helm/benchmark/scenarios/decodingtrust_stereotype_bias_scenario.py +13 -1
- helm/benchmark/scenarios/decodingtrust_toxicity_prompts_scenario.py +13 -1
- helm/benchmark/scenarios/dischargeme_scenario.py +24 -0
- helm/benchmark/scenarios/disinformation_scenario.py +22 -0
- helm/benchmark/scenarios/dyck_language_scenario.py +15 -0
- helm/benchmark/scenarios/ehrshot_scenario.py +22 -0
- helm/benchmark/scenarios/enem_challenge_scenario.py +19 -0
- helm/benchmark/scenarios/entity_data_imputation_scenario.py +14 -0
- helm/benchmark/scenarios/entity_matching_scenario.py +14 -0
- helm/benchmark/scenarios/financial_phrasebank_scenario.py +21 -0
- helm/benchmark/scenarios/gold_commodity_news_scenario.py +21 -0
- helm/benchmark/scenarios/gpqa_scenario.py +18 -0
- helm/benchmark/scenarios/grammar_scenario.py +20 -1
- helm/benchmark/scenarios/gsm_scenario.py +15 -0
- helm/benchmark/scenarios/headqa_scenario.py +22 -0
- helm/benchmark/scenarios/helpdesk_call_summarization_scenario.py +13 -0
- helm/benchmark/scenarios/ice_scenario.py +21 -1
- helm/benchmark/scenarios/ifeval_scenario.py +18 -0
- helm/benchmark/scenarios/imdb_scenario.py +15 -0
- helm/benchmark/scenarios/koala_scenario.py +21 -1
- helm/benchmark/scenarios/kpi_edgar_scenario.py +21 -0
- helm/benchmark/scenarios/legal_contract_summarization_scenario.py +20 -0
- helm/benchmark/scenarios/legal_summarization_scenario.py +50 -0
- helm/benchmark/scenarios/legal_support_scenario.py +13 -0
- helm/benchmark/scenarios/legalbench_scenario.py +20 -0
- helm/benchmark/scenarios/lex_glue_scenario.py +11 -0
- helm/benchmark/scenarios/lextreme_scenario.py +11 -0
- helm/benchmark/scenarios/lsat_qa_scenario.py +14 -0
- helm/benchmark/scenarios/madinah_qa_scenario.py +73 -0
- helm/benchmark/scenarios/math_scenario.py +26 -0
- helm/benchmark/scenarios/mbzuai_human_translated_arabic_mmlu.py +68 -0
- helm/benchmark/scenarios/med_dialog_scenario.py +32 -1
- helm/benchmark/scenarios/med_mcqa_scenario.py +14 -0
- helm/benchmark/scenarios/med_qa_scenario.py +14 -0
- helm/benchmark/scenarios/medalign_scenario.py +23 -0
- helm/benchmark/scenarios/medbullets_scenario.py +22 -0
- helm/benchmark/scenarios/medcalc_bench_scenario.py +22 -0
- helm/benchmark/scenarios/medec_scenario.py +23 -0
- helm/benchmark/scenarios/medhallu_scenario.py +23 -0
- helm/benchmark/scenarios/medhelm/__init__.py +0 -0
- helm/benchmark/scenarios/medhelm/judges.yaml +14 -0
- helm/benchmark/scenarios/medhelm_configurable_scenario.py +101 -0
- helm/benchmark/scenarios/medi_qa_scenario.py +23 -0
- helm/benchmark/scenarios/medication_qa_scenario.py +31 -1
- helm/benchmark/scenarios/mental_health_scenario.py +23 -0
- helm/benchmark/scenarios/mimic_bhc_scenario.py +24 -0
- helm/benchmark/scenarios/mimic_rrs_scenario.py +23 -0
- helm/benchmark/scenarios/mimiciv_billing_code_scenario.py +22 -0
- helm/benchmark/scenarios/mmlu_pro_scenario.py +18 -0
- helm/benchmark/scenarios/mmlu_scenario.py +15 -0
- helm/benchmark/scenarios/msmarco_scenario.py +30 -0
- helm/benchmark/scenarios/mtsamples_procedures_scenario.py +22 -0
- helm/benchmark/scenarios/mtsamples_replicate_scenario.py +22 -0
- helm/benchmark/scenarios/n2c2_ct_matching_scenario.py +20 -0
- helm/benchmark/scenarios/narrativeqa_scenario.py +20 -0
- helm/benchmark/scenarios/natural_qa_scenario.py +32 -0
- helm/benchmark/scenarios/omni_math_scenario.py +18 -0
- helm/benchmark/scenarios/open_assistant_scenario.py +22 -0
- helm/benchmark/scenarios/pubmed_qa_scenario.py +22 -0
- helm/benchmark/scenarios/quac_scenario.py +14 -0
- helm/benchmark/scenarios/race_based_med_scenario.py +23 -0
- helm/benchmark/scenarios/raft_scenario.py +15 -0
- helm/benchmark/scenarios/real_toxicity_prompts_scenario.py +14 -1
- helm/benchmark/scenarios/scenario.py +31 -0
- helm/benchmark/scenarios/seahelm_scenario.py +348 -0
- helm/benchmark/scenarios/self_instruct_scenario.py +29 -1
- helm/benchmark/scenarios/shc_bmt_scenario.py +22 -0
- helm/benchmark/scenarios/shc_cdi_scenario.py +20 -0
- helm/benchmark/scenarios/shc_conf_scenario.py +23 -0
- helm/benchmark/scenarios/shc_ent_scenario.py +21 -0
- helm/benchmark/scenarios/shc_gip_scenario.py +20 -0
- helm/benchmark/scenarios/shc_privacy_scenario.py +22 -0
- helm/benchmark/scenarios/shc_proxy_scenario.py +22 -0
- helm/benchmark/scenarios/shc_ptbm_scenario.py +23 -0
- helm/benchmark/scenarios/shc_sequoia_scenario.py +21 -0
- helm/benchmark/scenarios/situation_prompts.yaml +49 -0
- helm/benchmark/scenarios/starr_patient_instructions_scenario.py +22 -0
- helm/benchmark/scenarios/summarization_scenario.py +37 -0
- helm/benchmark/scenarios/synthetic_efficiency_scenario.py +22 -1
- helm/benchmark/scenarios/synthetic_reasoning_natural_scenario.py +13 -0
- helm/benchmark/scenarios/test_alrage_scenario.py +23 -0
- helm/benchmark/scenarios/test_arabic_exams_scenario.py +21 -0
- helm/benchmark/scenarios/test_aratrust_scenario.py +1 -1
- helm/benchmark/scenarios/test_bluex_scenario.py +2 -2
- helm/benchmark/scenarios/the_pile_scenario.py +13 -1
- helm/benchmark/scenarios/truthful_qa_scenario.py +14 -0
- helm/benchmark/scenarios/twitter_aae_scenario.py +20 -1
- helm/benchmark/scenarios/vicuna_scenario.py +21 -1
- helm/benchmark/scenarios/wikifact_scenario.py +20 -0
- helm/benchmark/scenarios/wildbench_scenario.py +18 -0
- helm/benchmark/scenarios/wmt_14_scenario.py +12 -0
- helm/benchmark/static/schema_arabic.yaml +55 -12
- helm/benchmark/static/schema_long_context.yaml +17 -17
- helm/benchmark/static/schema_medhelm.yaml +36 -0
- helm/benchmark/static/schema_slp.yaml +219 -0
- helm/benchmark/static_build/assets/index-671a5e06.js +10 -0
- helm/benchmark/static_build/assets/index-9352595e.css +1 -0
- helm/benchmark/static_build/index.html +2 -2
- helm/clients/audio_language/llama_omni/arguments.py +61 -0
- helm/clients/audio_language/llama_omni/constants.py +9 -0
- helm/clients/audio_language/llama_omni/conversation.py +213 -0
- helm/clients/audio_language/llama_omni/model/__init__.py +0 -0
- helm/clients/audio_language/llama_omni/model/builder.py +88 -0
- helm/clients/audio_language/llama_omni/model/language_model/omni_speech2s_llama.py +190 -0
- helm/clients/audio_language/llama_omni/model/language_model/omni_speech_llama.py +118 -0
- helm/clients/audio_language/llama_omni/model/omni_speech_arch.py +249 -0
- helm/clients/audio_language/llama_omni/model/speech_encoder/builder.py +9 -0
- helm/clients/audio_language/llama_omni/model/speech_encoder/speech_encoder.py +27 -0
- helm/clients/audio_language/llama_omni/model/speech_generator/builder.py +9 -0
- helm/clients/audio_language/llama_omni/model/speech_generator/generation.py +622 -0
- helm/clients/audio_language/llama_omni/model/speech_generator/speech_generator.py +104 -0
- helm/clients/audio_language/llama_omni/model/speech_projector/builder.py +9 -0
- helm/clients/audio_language/llama_omni/model/speech_projector/speech_projector.py +27 -0
- helm/clients/audio_language/llama_omni/preprocess.py +295 -0
- helm/clients/audio_language/llama_omni/utils.py +202 -0
- helm/clients/audio_language/qwen_omni/configuration_qwen2_5_omni.py +519 -0
- helm/clients/audio_language/qwen_omni/modeling_qwen2_5_omni.py +4308 -0
- helm/clients/audio_language/qwen_omni/processing_qwen2_5_omni.py +270 -0
- helm/clients/audio_language/qwen_omni/qwen2_5_omni_utils/__init__.py +0 -0
- helm/clients/audio_language/qwen_omni/qwen2_5_omni_utils/v2_5/__init__.py +8 -0
- helm/clients/audio_language/qwen_omni/qwen2_5_omni_utils/v2_5/audio_process.py +56 -0
- helm/clients/audio_language/qwen_omni/qwen2_5_omni_utils/v2_5/vision_process.py +380 -0
- helm/clients/image_generation/cogview2/sr_pipeline/dsr_model.py +1 -1
- helm/clients/image_generation/mindalle/models/stage1/layers.py +2 -2
- helm/clients/openai_client.py +31 -19
- helm/clients/openai_responses_client.py +27 -3
- helm/clients/openrouter_client.py +31 -0
- helm/clients/test_openrouter_client.py +69 -0
- helm/clients/together_client.py +48 -11
- helm/clients/vertexai_client.py +8 -2
- helm/config/model_deployments.yaml +75 -1
- helm/config/model_metadata.yaml +70 -2
- helm/config/tokenizer_configs.yaml +19 -1
- helm/proxy/example_queries.py +8 -8
- helm/proxy/server.py +2 -1
- helm/proxy/static/index.css +4 -0
- helm/proxy/static/index.js +7 -1
- helm/benchmark/metrics/aci_bench_metrics.py +0 -14
- helm/benchmark/metrics/chw_care_plan_metrics.py +0 -14
- helm/benchmark/metrics/dischargeme_metrics.py +0 -14
- helm/benchmark/metrics/med_dialog_metrics.py +0 -14
- helm/benchmark/metrics/medalign_metrics.py +0 -14
- helm/benchmark/metrics/medi_qa_metrics.py +0 -14
- helm/benchmark/metrics/medication_qa_metrics.py +0 -14
- helm/benchmark/metrics/mental_health_metrics.py +0 -14
- helm/benchmark/metrics/mimic_bhc_metrics.py +0 -14
- helm/benchmark/metrics/mimic_rrs_metrics.py +0 -14
- helm/benchmark/metrics/mtsamples_procedures_metrics.py +0 -14
- helm/benchmark/metrics/mtsamples_replicate_metrics.py +0 -14
- helm/benchmark/metrics/starr_patient_instructions_metrics.py +0 -14
- helm/benchmark/static_build/assets/index-b9779128.css +0 -1
- helm/benchmark/static_build/assets/index-e439d5e1.js +0 -10
- {crfm_helm-0.5.7.dist-info → crfm_helm-0.5.8.dist-info}/WHEEL +0 -0
- {crfm_helm-0.5.7.dist-info → crfm_helm-0.5.8.dist-info}/entry_points.txt +0 -0
- {crfm_helm-0.5.7.dist-info → crfm_helm-0.5.8.dist-info}/licenses/LICENSE +0 -0
- {crfm_helm-0.5.7.dist-info → crfm_helm-0.5.8.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2025 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
"""
|
|
17
|
+
Processor class for Qwen2.5Omni.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import logging
|
|
21
|
+
from typing import List, Optional, Union
|
|
22
|
+
|
|
23
|
+
import numpy as np
|
|
24
|
+
import torch
|
|
25
|
+
|
|
26
|
+
from transformers.feature_extraction_utils import BatchFeature
|
|
27
|
+
from transformers.image_utils import ImageInput, VideoInput
|
|
28
|
+
from transformers.processing_utils import ProcessingKwargs, ProcessorMixin, Unpack
|
|
29
|
+
from transformers.tokenization_utils_base import PaddingStrategy, PreTokenizedInput, TextInput
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Qwen2_5OmniProcessorKwargs(ProcessingKwargs):
|
|
33
|
+
_defaults = {
|
|
34
|
+
"text_kwargs": {
|
|
35
|
+
"padding": False,
|
|
36
|
+
"padding_side": "left",
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Qwen2_5OmniProcessor(ProcessorMixin):
|
|
42
|
+
|
|
43
|
+
attributes = ["omni_processor", "feature_extractor", "tokenizer"]
|
|
44
|
+
omni_processor_class = "Qwen2VLImageProcessor"
|
|
45
|
+
feature_extractor_class = "WhisperFeatureExtractor"
|
|
46
|
+
tokenizer_class = ("Qwen2Tokenizer", "Qwen2TokenizerFast")
|
|
47
|
+
valid_kwargs = ["chat_template"]
|
|
48
|
+
|
|
49
|
+
def __init__(self, omni_processor=None, feature_extractor=None, tokenizer=None, chat_template=None):
|
|
50
|
+
self.image_token = "<|IMAGE|>"
|
|
51
|
+
self.audio_token = "<|AUDIO|>"
|
|
52
|
+
self.video_token = "<|VIDEO|>"
|
|
53
|
+
self.vision_bos_token = "<|vision_bos|>"
|
|
54
|
+
self.vision_eos_token = "<|vision_eos|>"
|
|
55
|
+
self.audio_bos_token = "<|audio_bos|>"
|
|
56
|
+
self.audio_eos_token = "<|audio_eos|>"
|
|
57
|
+
super().__init__(omni_processor, feature_extractor, tokenizer, chat_template=chat_template)
|
|
58
|
+
|
|
59
|
+
def __call__(
|
|
60
|
+
self,
|
|
61
|
+
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,
|
|
62
|
+
images: ImageInput = None,
|
|
63
|
+
videos: VideoInput = None,
|
|
64
|
+
audios: Optional[Union[np.ndarray, List[np.ndarray]]] = None,
|
|
65
|
+
sampling_rate: Optional[int] = 16000,
|
|
66
|
+
fps: Optional[List[float]] = None,
|
|
67
|
+
padding: Union[bool, str, PaddingStrategy] = False,
|
|
68
|
+
use_audio_in_video: Optional[bool] = False,
|
|
69
|
+
position_id_per_seconds: int = 25,
|
|
70
|
+
seconds_per_chunk: float = 2.0,
|
|
71
|
+
**kwargs: Unpack[Qwen2_5OmniProcessorKwargs],
|
|
72
|
+
) -> BatchFeature:
|
|
73
|
+
|
|
74
|
+
output_kwargs = self._merge_kwargs(
|
|
75
|
+
Qwen2_5OmniProcessorKwargs,
|
|
76
|
+
tokenizer_init_kwargs=self.tokenizer.init_kwargs,
|
|
77
|
+
padding=padding,
|
|
78
|
+
**kwargs,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
if audios is not None:
|
|
82
|
+
audios_inputs = self.feature_extractor(
|
|
83
|
+
audios, sampling_rate=sampling_rate, return_attention_mask=True, padding="max_length", **kwargs
|
|
84
|
+
)
|
|
85
|
+
audios_inputs["feature_attention_mask"] = audios_inputs.pop(
|
|
86
|
+
"attention_mask"
|
|
87
|
+
) # rename feature_attention_mask to prevent conflicts later on
|
|
88
|
+
audios_inputs["input_features"] = audios_inputs.pop(
|
|
89
|
+
"input_features"
|
|
90
|
+
) # rename input_features to prevent conflicts later on
|
|
91
|
+
input_lengths = (audios_inputs["feature_attention_mask"].sum(-1).numpy() - 1) // 2 + 1
|
|
92
|
+
audio_lengths = (input_lengths - 2) // 2 + 1
|
|
93
|
+
else:
|
|
94
|
+
audios_inputs = {}
|
|
95
|
+
audio_lengths = None
|
|
96
|
+
|
|
97
|
+
if images is not None:
|
|
98
|
+
images_inputs = self.omni_processor(images=images, videos=None, **output_kwargs["images_kwargs"])
|
|
99
|
+
image_grid_thw = images_inputs["image_grid_thw"]
|
|
100
|
+
else:
|
|
101
|
+
images_inputs = {}
|
|
102
|
+
image_grid_thw = None
|
|
103
|
+
|
|
104
|
+
if videos is not None:
|
|
105
|
+
videos_inputs = self.omni_processor(images=None, videos=videos, **output_kwargs["videos_kwargs"])
|
|
106
|
+
if fps is None:
|
|
107
|
+
fps = [2.0] * len(videos)
|
|
108
|
+
videos_inputs["video_second_per_grid"] = [
|
|
109
|
+
self.omni_processor.temporal_patch_size / fps[i] for i in range(len(fps))
|
|
110
|
+
]
|
|
111
|
+
video_grid_thw = videos_inputs["video_grid_thw"]
|
|
112
|
+
else:
|
|
113
|
+
videos_inputs = {}
|
|
114
|
+
video_grid_thw = None
|
|
115
|
+
|
|
116
|
+
if text is None:
|
|
117
|
+
raise ValueError("You need to specify either a `text` input to process.")
|
|
118
|
+
|
|
119
|
+
if not isinstance(text, list):
|
|
120
|
+
text = [text]
|
|
121
|
+
|
|
122
|
+
merge_length = self.omni_processor.merge_size**2
|
|
123
|
+
audio_index = 0
|
|
124
|
+
image_index = 0
|
|
125
|
+
video_index = 0
|
|
126
|
+
for i in range(len(text)):
|
|
127
|
+
positions = []
|
|
128
|
+
for special_token in [self.audio_token, self.image_token, self.video_token]:
|
|
129
|
+
start = 0
|
|
130
|
+
while True:
|
|
131
|
+
pos = text[i].find(special_token, start)
|
|
132
|
+
if pos == -1:
|
|
133
|
+
break
|
|
134
|
+
positions.append((pos, special_token))
|
|
135
|
+
start = pos + len(special_token)
|
|
136
|
+
positions.sort(key=lambda x: x[0])
|
|
137
|
+
for _, special_token in positions:
|
|
138
|
+
if audios is not None and special_token == self.audio_token:
|
|
139
|
+
text[i] = text[i].replace(
|
|
140
|
+
self.audio_token,
|
|
141
|
+
"<|audio_placeholder|>" * audio_lengths[audio_index],
|
|
142
|
+
1,
|
|
143
|
+
)
|
|
144
|
+
audio_index += 1
|
|
145
|
+
elif images is not None and special_token == self.image_token:
|
|
146
|
+
text[i] = text[i].replace(
|
|
147
|
+
self.image_token,
|
|
148
|
+
"<|image_placeholder|>" * (image_grid_thw[image_index].prod() // merge_length),
|
|
149
|
+
1,
|
|
150
|
+
)
|
|
151
|
+
image_index += 1
|
|
152
|
+
elif videos is not None and special_token == self.video_token:
|
|
153
|
+
if use_audio_in_video:
|
|
154
|
+
audio_t_index = torch.arange(audio_lengths[audio_index])
|
|
155
|
+
video_t_index = (
|
|
156
|
+
torch.arange(video_grid_thw[video_index][0])
|
|
157
|
+
.view(-1, 1, 1)
|
|
158
|
+
.expand(
|
|
159
|
+
-1,
|
|
160
|
+
video_grid_thw[video_index][1] // self.omni_processor.merge_size,
|
|
161
|
+
video_grid_thw[video_index][2] // self.omni_processor.merge_size,
|
|
162
|
+
)
|
|
163
|
+
.flatten()
|
|
164
|
+
* videos_inputs["video_second_per_grid"][video_index]
|
|
165
|
+
* position_id_per_seconds
|
|
166
|
+
).long()
|
|
167
|
+
t_ntoken_per_chunk = int(position_id_per_seconds * seconds_per_chunk)
|
|
168
|
+
video_chunk_indexes = self.get_chunked_index(video_t_index, t_ntoken_per_chunk)
|
|
169
|
+
audio_chunk_indexes = self.get_chunked_index(audio_t_index, t_ntoken_per_chunk)
|
|
170
|
+
placeholder_string = str()
|
|
171
|
+
placeholder_string += self.vision_bos_token + self.audio_bos_token
|
|
172
|
+
for j in range(max(len(video_chunk_indexes), len(audio_chunk_indexes))):
|
|
173
|
+
video_chunk_index = video_chunk_indexes[j] if j < len(video_chunk_indexes) else None
|
|
174
|
+
audio_chunk_index = audio_chunk_indexes[j] if j < len(audio_chunk_indexes) else None
|
|
175
|
+
if video_chunk_index is not None:
|
|
176
|
+
placeholder_string += "<|video_placeholder|>" * (
|
|
177
|
+
video_chunk_index[1] - video_chunk_index[0]
|
|
178
|
+
)
|
|
179
|
+
if audio_chunk_index is not None:
|
|
180
|
+
placeholder_string += "<|audio_placeholder|>" * (
|
|
181
|
+
audio_chunk_index[1] - audio_chunk_index[0]
|
|
182
|
+
)
|
|
183
|
+
placeholder_string += self.audio_eos_token + self.vision_eos_token
|
|
184
|
+
text[i] = text[i].replace(
|
|
185
|
+
self.vision_bos_token + self.video_token + self.vision_eos_token,
|
|
186
|
+
placeholder_string,
|
|
187
|
+
1,
|
|
188
|
+
)
|
|
189
|
+
audio_index += 1
|
|
190
|
+
video_index += 1
|
|
191
|
+
else:
|
|
192
|
+
text[i] = text[i].replace(
|
|
193
|
+
self.video_token,
|
|
194
|
+
"<|video_placeholder|>" * (video_grid_thw[video_index].prod() // merge_length),
|
|
195
|
+
1,
|
|
196
|
+
)
|
|
197
|
+
video_index += 1
|
|
198
|
+
|
|
199
|
+
text[i] = text[i].replace("<|audio_placeholder|>", self.audio_token)
|
|
200
|
+
text[i] = text[i].replace("<|image_placeholder|>", self.image_token)
|
|
201
|
+
text[i] = text[i].replace("<|video_placeholder|>", self.video_token)
|
|
202
|
+
|
|
203
|
+
texts_inputs = self.tokenizer(text, **output_kwargs["text_kwargs"])
|
|
204
|
+
|
|
205
|
+
return BatchFeature(
|
|
206
|
+
data={**texts_inputs, **images_inputs, **videos_inputs, **audios_inputs},
|
|
207
|
+
tensor_type=kwargs.get("return_tensors"),
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
def get_chunked_index(self, t_index, t_ntoken_per_chunk):
|
|
211
|
+
def _iter():
|
|
212
|
+
i, start_idx = 0, 0 # skip bos token
|
|
213
|
+
current_chunk = 1
|
|
214
|
+
while i < len(t_index): # skip eos token
|
|
215
|
+
if t_index[i] >= current_chunk * t_ntoken_per_chunk:
|
|
216
|
+
yield (start_idx, i)
|
|
217
|
+
start_idx = i
|
|
218
|
+
current_chunk += 1
|
|
219
|
+
i += 1
|
|
220
|
+
yield (start_idx, len(t_index))
|
|
221
|
+
|
|
222
|
+
return list(_iter())
|
|
223
|
+
|
|
224
|
+
def batch_decode(self, *args, **kwargs):
|
|
225
|
+
"""
|
|
226
|
+
This method forwards all its arguments to Qwen2TokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
|
|
227
|
+
refer to the docstring of this method for more information.
|
|
228
|
+
"""
|
|
229
|
+
return self.tokenizer.batch_decode(*args, **kwargs)
|
|
230
|
+
|
|
231
|
+
def decode(self, *args, **kwargs):
|
|
232
|
+
"""
|
|
233
|
+
This method forwards all its arguments to Qwen2TokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
|
|
234
|
+
the docstring of this method for more information.
|
|
235
|
+
"""
|
|
236
|
+
return self.tokenizer.decode(*args, **kwargs)
|
|
237
|
+
|
|
238
|
+
def apply_chat_template(self, conversations, chat_template=None, **kwargs):
|
|
239
|
+
if isinstance(conversations[0], dict):
|
|
240
|
+
conversations = [conversations]
|
|
241
|
+
for conversation in conversations:
|
|
242
|
+
if conversation[0]["role"] != "system" or conversation[0]["content"] != (
|
|
243
|
+
"You are Qwen, a virtual human developed by the Qwen Team, Alibaba Group, capable"
|
|
244
|
+
" of perceiving auditory and visual inputs, as well as generating text and speech."
|
|
245
|
+
):
|
|
246
|
+
logging.warning(
|
|
247
|
+
"System prompt modified, audio output may not work as expected. "
|
|
248
|
+
"Audio output mode only works when using default system prompt 'You are Qwen,"
|
|
249
|
+
" a virtual human developed by the Qwen Team, Alibaba Group, capable of perceiving"
|
|
250
|
+
" auditory and visual inputs, as well as generating text and speech.'"
|
|
251
|
+
)
|
|
252
|
+
return super().apply_chat_template(conversations, chat_template, **kwargs)
|
|
253
|
+
|
|
254
|
+
@property
|
|
255
|
+
def model_input_names(self):
|
|
256
|
+
tokenizer_input_names = self.tokenizer.model_input_names
|
|
257
|
+
feature_extractor_input_names = self.feature_extractor.model_input_names
|
|
258
|
+
omni_processor_input_names = self.omni_processor.model_input_names
|
|
259
|
+
return list(
|
|
260
|
+
dict.fromkeys(
|
|
261
|
+
tokenizer_input_names
|
|
262
|
+
+ feature_extractor_input_names
|
|
263
|
+
+ omni_processor_input_names
|
|
264
|
+
+ ["feature_attention_mask"]
|
|
265
|
+
+ ["video_second_per_grid"]
|
|
266
|
+
)
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
__all__ = ["Qwen2_5OmniProcessor"]
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from .audio_process import process_audio_info
|
|
2
|
+
from .vision_process import process_vision_info
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def process_mm_info(conversations, use_audio_in_video, return_video_kwargs=False):
|
|
6
|
+
audios = process_audio_info(conversations, use_audio_in_video)
|
|
7
|
+
vision = process_vision_info(conversations, return_video_kwargs=return_video_kwargs)
|
|
8
|
+
return (audios,) + vision
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import audioread
|
|
2
|
+
import av
|
|
3
|
+
import librosa
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _check_if_video_has_audio(video_path):
|
|
8
|
+
container = av.open(video_path)
|
|
9
|
+
audio_streams = [stream for stream in container.streams if stream.type == "audio"]
|
|
10
|
+
if not audio_streams:
|
|
11
|
+
return False
|
|
12
|
+
return True
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def process_audio_info(conversations, use_audio_in_video: bool):
|
|
16
|
+
audios = []
|
|
17
|
+
if isinstance(conversations[0], dict):
|
|
18
|
+
conversations_p = [conversations]
|
|
19
|
+
for conversation in conversations_p:
|
|
20
|
+
for message in conversation:
|
|
21
|
+
if not isinstance(message["content"], list):
|
|
22
|
+
continue
|
|
23
|
+
for ele in message["content"]:
|
|
24
|
+
if ele["type"] == "audio":
|
|
25
|
+
if "audio" in ele:
|
|
26
|
+
path = ele["audio"]
|
|
27
|
+
if path.startswith("http://") or path.startswith("https://"):
|
|
28
|
+
audios.append(librosa.load(audioread.ffdec.FFmpegAudioFile(path), sr=16000)[0])
|
|
29
|
+
elif isinstance(path, np.ndarray):
|
|
30
|
+
if path.ndim > 1:
|
|
31
|
+
raise ValueError("Support only mono audio")
|
|
32
|
+
audios.append(path)
|
|
33
|
+
elif path.startswith("file://"):
|
|
34
|
+
audios.append(librosa.load(path[len("file://") :], sr=16000)[0])
|
|
35
|
+
else:
|
|
36
|
+
audios.append(librosa.load(path, sr=16000)[0])
|
|
37
|
+
else:
|
|
38
|
+
raise ValueError("Unknown audio {}".format(ele))
|
|
39
|
+
if use_audio_in_video and ele["type"] == "video":
|
|
40
|
+
if "video" in ele:
|
|
41
|
+
path = ele["video"]
|
|
42
|
+
assert _check_if_video_has_audio(
|
|
43
|
+
path
|
|
44
|
+
), "Video must has audio track when use_audio_in_video=True"
|
|
45
|
+
if path.startswith("http://") or path.startswith("https://"):
|
|
46
|
+
audios.append(librosa.load(audioread.ffdec.FFmpegAudioFile(path), sr=16000)[0])
|
|
47
|
+
elif path.startswith("file://"):
|
|
48
|
+
audios.append(librosa.load(path[len("file://") :], sr=16000)[0])
|
|
49
|
+
else:
|
|
50
|
+
audios.append(librosa.load(path, sr=16000)[0])
|
|
51
|
+
else:
|
|
52
|
+
raise ValueError("Unknown video {}".format(ele))
|
|
53
|
+
if len(audios) == 0:
|
|
54
|
+
return None
|
|
55
|
+
else:
|
|
56
|
+
return audios
|