(self, models_root_path, device_map="auto", torch_dtype="bfloat16")
| 25 | |
| 26 | class PromptEnhancerV2: |
| 27 | def __init__(self, models_root_path, device_map="auto", torch_dtype="bfloat16"): |
| 28 | if not logging.getLogger(__name__).handlers: |
| 29 | logging.basicConfig(level=logging.INFO) |
| 30 | self.logger = logging.getLogger(__name__) |
| 31 | |
| 32 | # dtype 兼容处理 |
| 33 | if torch_dtype == "bfloat16": |
| 34 | dtype = torch.bfloat16 |
| 35 | elif torch_dtype == "float16": |
| 36 | dtype = torch.float16 |
| 37 | else: |
| 38 | dtype = torch.float32 |
| 39 | |
| 40 | self.model = Qwen2_5_VLForConditionalGeneration.from_pretrained( |
| 41 | models_root_path, |
| 42 | torch_dtype=dtype, |
| 43 | attn_implementation="flash_attention_2", |
| 44 | device_map=device_map, |
| 45 | ) |
| 46 | self.processor = AutoProcessor.from_pretrained(models_root_path) |
| 47 | |
| 48 | @torch.inference_mode() |
| 49 | def predict( |
nothing calls this directly
no outgoing calls
no test coverage detected