MedGemma, 내 노트북에 안전하게 모셔오는 법[pe]
MedGemma, 내 노트북에 안전하게 모셔오는 법[pe]
(4B·27B 설치 요구사항과 단계별 가이드)
MedGemma 설치 전체 개요
MedGemma(메드제마)는 Gemma 3 기반의 의료 특화 모델로, 4B 멀티모달(이미지+텍스트)와 27B 텍스트 전용/멀티모달 버전이 있다.+2
설치·구동은 크게
① 어디서 돌릴지 결정(로컬 vs 클라우드)
② 하드웨어 요구사항 확인
③ 파이썬/라이브러리 환경 구축
④ 모델 다운로드·테스트 네 단계로 정리할 수 있다.+2
하드웨어 요구사항 정리 (4B vs 27B)
기본 공식 정보와 특징
MedGemma는 “로컬·클라우드 어디서든 돌릴 수 있게” 스냅샷 형태로 배포되며, 4B/27B 두 계열 모두 NVIDIA GPU 사용을 강력히 권장한다.+2
4B 멀티모달 모델은 흉부 X-ray, 피부/안과 영상 같은 의료 이미지+텍스트 작업을 위한 경량 버전이고,+1
27B 텍스트 모델은 EHR 이해, 임상 추론, 복잡한 의료 QA에 더 적합하다.+1
실전 하드웨어 요구사항 (요약)
MedGemma 4B (멀티모달 기준)+1
최소 GPU: NVIDIA RTX 3060/3070급 이상 (6–8GB VRAM), 권장 RTX 4090 / A6000 / A100+1
VRAM: 최소 8–12GB, 권장 16GB 이상 (4bit/8bit 양자화 시 더 여유).+1
디스크: 모델·캐시 포함 8–16GB 이상 여유.+1
MedGemma 27B (텍스트 전용 또는 멀티모달)+2
실무에서는 4bit GGI/ GGUF 등 양자화 모델을 써서 12–16GB VRAM에도 억지로 올리는 사례가 있지만, 속도·안정성은 떨어질 수 있다.+1
재미있는 한 줄
“모델은 살찌는데, GPU는 그대로다. 그럴 땐 ‘다이어트 버전(양자화)’을 쓰거나, 아예 ‘작은 동생(4B)’을 먼저 써보라.”+1
소프트웨어 요구사항 및 공통 준비
STEP 1. 운영체제 및 드라이버
OS: Linux(Ubuntu 20.04+), WSL2, macOS(MPS, 단 성능 제한), Windows+CUDA 모두 가능하나, 의료용으로는 리눅스+NVIDIA 조합이 가장 흔하다.+1
드라이버: GPU에 맞는 NVIDIA 드라이버와 CUDA Toolkit 설치. NodeShift·GCP·Vertex AI 같은 클라우드에서는 CUDA 이미지를 선택하면 대부분 자동 구성된다.+1
STEP 2. 파이썬 환경
Python 3.10 또는 3.11 권장, 가상환경(Anaconda/venv) 사용.+1
예시 (conda):
bashconda create -n medgemma python=3.11 -y conda activate medgemma
STEP 3. 필수 라이브러리
PyTorch(+CUDA), transformers, accelerate, bitsandbytes, sentencepiece, huggingface_hub 등이 필요하다.+1
예시 (pip):
bashpip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 pip install "transformers>=4.50.0" "accelerate" bitsandbytes sentencepiece protobuf pip install huggingface_hub einops timm pillow numpy
Hugging Face·Google 환경 준비
STEP 4. Hugging Face 계정 및 토큰
MedGemma 공식 모델은 Hugging Face 모델 허브 구글 계정 아래에 올라와 있으며, 접근하려면 HF 계정과 read 토큰이 필요하다.+3
절차:
로컬/Colab에서 huggingface_hub.login()으로 로그인:
pythonfrom huggingface_hub import login login("발급받은_HF_토큰")
STEP 5. Vertex AI/Google Cloud에서 쓰는 경우
이 경우 로컬에 모델을 다운로드할 필요 없이, GCP에서 관리하는 GPU 인프라를 그대로 활용한다.+1
MedGemma 4B 설치·테스트 절차 (로컬/Colab 공통)
텍스트+이미지 멀티모달 4B 모델 기준 절차이다.+1
STEP 6. 모델 ID 선택
Hugging Face에서 사용할 모델 ID 예시:+1
멀티모달: google/medgemma-1.5-4b-it
텍스트 전용(경량): 커뮤니티 양자화 모델들(예: GGUF, FP8 등)
STEP 7. 멀티모달 모델·프로세서 로드
pythonfrom transformers import AutoProcessor, AutoModelForVision2Seq import torch model_id = "google/medgemma-1.5-4b-it" processor = AutoProcessor.from_pretrained(model_id) model = AutoModelForVision2Seq.from_pretrained( model_id, device_map="auto", torch_dtype=torch.bfloat16, # 또는 torch.float16 ) model.eval()
STEP 8. 간단 멀티모달 질의 테스트
공개 X-ray 이미지를 불러와, 한글 프롬프트로 질문하는 예시:
pythonfrom PIL import Image import requests url = "https://upload.wikimedia.org/wikipedia/commons/c/c8/Chest_Xray_PA_3-8-2010.png" image = Image.open(requests.get(url, stream=True).raw) messages = [ { "role": "user", "content": [ {"type": "image", "image": image}, { "type": "text", "text": ( "이 흉부 X-ray에서 눈에 띄는 이상 소견을 설명해 주세요. " "단, 최종 진단은 내리지 말고, 전문의 추가 판독이 필요하다고 명시하세요." ), }, ], } ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, return_tensors="pt" ).to(model.device) with torch.no_grad(): output_ids = model.generate( **inputs, max_new_tokens=512, do_sample=False, ) answer = processor.batch_decode(output_ids, skip_special_tokens=True)[0] print(answer)
MedGemma 27B 설치·요구사항 체크
STEP 9. 27B 텍스트 모델 설치 준비
VRAM 32GB 이상 GPU가 없다면, GGUF/FP8 등 양자화 버전을 LM Studio·llama.cpp 등으로 구동하는 편이 현실적이다.+1
로컬 파이썬 예시 (대형 GPU 전제):
pythonfrom transformers import AutoModelForCausalLM, AutoTokenizer import torch model_id = "google/medgemma-27b-text-it" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained( model_id, device_map="auto", torch_dtype=torch.bfloat16, ) prompt = "당뇨병 환자의 고혈압 치료에서 ACE 억제제 사용 시 주의사항을 설명해 주세요." inputs = tokenizer(prompt, return_tensors="pt").to(model.device) with torch.no_grad(): out_ids = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(out_ids[0], skip_special_tokens=True))
STEP 10. GGUF/LM Studio 등 경량 실행 (옵션)
LM Studio / Ollama 같은 툴에서 MedGemma 27B GGUF 또는 FP8 모델을 선택하면, VRAM 16GB급에서도 어느 정도 실행 가능하다.+1
이 경우 설치 절차는:
보안·규제·성능 튜닝 관련 요구사항
STEP 11. 데이터 보안·프라이버시
MedGemma는 비식별화된 의료 데이터로 학습됐지만, 사용자가 입력하는 EHR·영상에는 여전히 개인정보가 포함될 수 있다.+1
Google 공식 가이드:
특정 기관·용도에 쓰기 전에는 자체 검증이 필수이고,+1
PHI(개인 건강 정보)가 포함된 데이터를 처리할 때는 기관의 보안·규제 정책을 반드시 준수해야 한다.+1
STEP 12. 성능 튜닝·추가 요구사항
Google Health는 MedGemma를 “기본 모델”로 제시하며, 실제 사용 사례에서는 프롬프트 엔지니어링, 파인튜닝, 에이전트 오케스트레이션이 필요하다고 명시한다.+1
이를 위해서는 추가적으로 다음이 필요할 수 있다.
상세 참고문헌·사이트
Google Health – MedGemma 개요/가이드
https://developers.google.com/health-ai-developer-foundations/medgemmaMedGemma 1.5 Model Card (데이터·훈련·사용법)
https://developers.google.com/health-ai-developer-foundations/medgemma/model-cardGoogle Research Blog – MedGemma: Our most capable open models for health AI development
https://research.google/blog/medgemma-our-most-capable-open-models-for-health-ai-development/MedGemma GitHub (공식 노트북·CT 데모 등)
https://github.com/Google-Health/medgemma+1Hugging Face – google/medgemma-1.5-4b-it
https://huggingface.co/google/medgemma-1.5-4b-itHugging Face – google/medgemma-27b-text-it
https://huggingface.co/google/medgemma-27b-text-itDev.to – Build Medical AI with Google’s MedGemma 4B & 27B (로컬 설치 튜토리얼, HW 요구사항 상세)
https://dev.to/nodeshiftcloud/build-medical-ai-with-googles-medgemma-4b-27b-a-complete-installation-guide-1pb3GGUF/FP8 커뮤니티 포트 – medgemma-27b-text-it-GGUF
https://huggingface.co/Mungert/medgemma-27b-text-it-GGUFMedGemma 로컬 사용 가이드 (LM Studio·CPU/GPU 요구사항 표)
https://www.averoxglobalsolutions.com/post/medgemma-healthcare-ai-local-use
(라벨링: 위 설치·요구사항 정리는 Google 공식 문서·블로그·GitHub 노트북과, Dev.to·LM Studio 가이드의 HW 요구사항을 종합한 내용이다 – [추가정보].)+5
요약
MedGemma 4B는 VRAM 8–16GB급 GPU에서도 멀티모달 의료 작업을 테스트할 수 있는 경량 모델이고, 27B는 VRAM 32GB 이상 또는 양자화 기반 환경이 사실상 필요하다.+2
설치는 파이썬 3.10+환경과 PyTorch/Transformers, HF 토큰 준비만 되어 있으면 Hugging Face/Vertex AI에서 곧바로 불러올 수 있으며, Dev.to·GitHub 노트북을 그대로 따라 하면 수십 분 안에 첫 의료 QA·X-ray 데모까지 실행 가능하다.+3
실제 의료 현장에 투입하기 전에는 보안·프라이버시·성능 검증이 필수이며, 기관 규정에 맞는 인프라(GCP·온프레미스 GPU)와 평가 파이프라인을 갖추는 것이 요구된다.+3
태그검색
#MedGemma #의료AI #HealthAI #의료LLM #멀티모달모델 #4B모델 #27B모델 #GPU요구사항 #의료AI설치 #HuggingFace #VertexAI #의료딥러닝 #모델배포
Blogger / Blogspot 150자 검색설명
“MedGemma 설치, 사양이 복잡해 막막한가요? 4B·27B 의료 AI를 위한 GPU·RAM·설치 단계를 10분 만에 정리한 가이드로, ‘이제 나도 병원급 AI 쓴다!’는 든든함을 느껴보세요!”
댓글
댓글 쓰기