1、创建虚拟环境: conda create -n medgemma python=3.10 -y && conda activate medgemma 2、克隆项目 git clone https://githubfast.com/Google-Health/medgemma.git cd medgemma 3、安装项目相关依赖: pip install --upgrade transformers[torch] accelerate bitsandbytes torch pillow gradio requests pillow timm -i https://pypi.tuna.tsinghua.edu.cn/simple 4、配置模型下载的相关库: pip install -U huggingface_hub -i https://pypi.tuna.tsinghua.edu.cn/simple export HF_ENDPOINT=https://hf-mirror.com (模型下载前需要先去huggingface上找到谷歌的这个项目获取授权) https://huggingface.co/google/medgemma-4b-it 5、编写测试代码app.py: #!/usr/bin/env python # -*- coding: utf-8 -*- from transformers import AutoProcessor, AutoModelForImageTextToText from PIL import Image import torch # ———— (可选)显式开启 TorchDynamo ———— # torch._dynamo.enable() # 模型标识 model_id = "google/medgemma-4b-it" # 加载模型(不禁用 Dynamo) model = AutoModelForImageTextToText.from_pretrained( model_id, torch_dtype=torch.bfloat16, device_map="auto", ) # 加载预处理器 processor = Aut...