from transformers import Qwen3VLForConditionalGeneration, AutoProcessor, BitsAndBytesConfigimport osimport torch cpu_count = os.cpu_count()print(f"Number of CPU cores in the system: {cpu_count}")half_cpu_count = cpu_count // 2os.environ["MKL_NUM_THREADS"] = str(half_cpu_count)os.environ["OMP_NUM_THREADS"] = str(half_cpu_count)torch.set_num_threads(half_cpu_count) MODEL_ID = "huihui-ai/Huihui-Qwen3-VL-4B-Instruct-abliterated-FP8" # default: Load the model on the available device(s)model = Qwen3VLForConditionalGeneration.from_pretrained( MODEL_ID, device_map="auto", trust_remote_code=True, dtype=torch.bfloat16, low_cpu_mem_usage=True,)# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.# model = Qwen3VLForConditionalGeneration.from_pretrained(# "Qwen/Qwen3-VL-235B-A22B-Instruct",# dtype=torch.bfloat16,# attn_implementation="flash_attention_2",# device_map="auto",# ) processor = AutoProcessor.from_pretrained(MODEL_ID) image_path = "/png/cars.jpg" messages = [ { "role": "user", "content": [ { "type": "image", "image": f"{image_path}", }, {"type": "text", "text": "Describe this image."}, ], }] # Preparation for inferenceinputs = processor.apply_chat_template( messages, tokenize=True, add_generation_prompt=True, return_dict=True, return_tensors="pt").to(model.device) # Inference: Generation of the outputgenerated_ids = model.generate(**inputs, max_new_tokens=128)generated_ids_trimmed = [ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]output_text = processor.batch_decode( generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)print(output_text)