NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty() instead of torch.nn.Module.to() when moving module from meta to a different device.
·
Error Note
[문제 상황] python 멀티 스레드 실행시, model을 .to('cpu') 또는 .to('cuda')등 모델을 cpu나 gpu에 올릴때 발생하는 에러입니다. (멀티스레드로 실행하지 않으면 에러 발생하지 않음) [문제 원인] 메타로 만들어진 모듈을 아직 실제 텐서로 채우기 전에 .to()를 호출하는 코드 경로가 스레드에서만 발생하기 때문이에요. 보통 아래 패턴들 때문에 스레드 경로에서만 메타가 남습니다. - 왜 스레드에서만 메타 텐서가 남을까? 모델 생성/로드 순서가 스레드와 메인에서 다름메인 스레드: from_pretrained(..., low_cpu_mem_usage=False) 처럼 바로 실제 텐서로 초기화 → .to() 가능워커 스레드: from_pretrained(..., low_cpu_m..
[Pytorch] python 멀티스레드와 torch.cuda.empty_cache()
·
Pytorch
[문제 현상] python에서 멀티스레드로 각 스레드마다 사용 해야 할 gpu인덱스 설정 후, 딥러닝 모델을 잠시 cpu로 내리고 torch.cuda.empty_cache() 를 해주면 지정한 gpu외에 갑자기 0번 메모리가 잡히기 시작하는 현상이 있었습니다. chatgpt에 의한 원인과 해결방법은 아래와 같습니다. [원인 및 해결방법] - by ChatGPT torch.cuda.empty_cache() 는 “현재 스레드의 현재 디바이스(current device)”의 캐시만 비우는데, 이걸 부르는 순간 그 디바이스의 CUDA 컨텍스트가 없으면 새로 초기화해요. 스레드에서 current device를 안 정했으면 기본이 cuda:0 이라서, 빈 캐시를 비우려다 오히려 GPU0 컨텍스트가 생성→수 MB..
[1] Learning Transferable Visual Models From Natural Language Supervision(CLIP)
·
Paper Review/LLM & VLM
[Paper] https://arxiv.org/pdf/2103.00020[Github] https://github.com/OpenAI/CLIP GitHub - openai/CLIP: CLIP (Contrastive Language-Image Pretraining), Predict the most relevant text snippet given an imageCLIP (Contrastive Language-Image Pretraining), Predict the most relevant text snippet given an image - openai/CLIPgithub.com 1. Abstract 기존 연구의 문제점: 한정된 클래스만을 가지고 학습 ⇒ generality 와 usability에 한계가..
[Pytorch] Running FLUX.1-Kontext-dev and Qwen-Image-Edit on rtx3090
·
Pytorch
FLUX.1-Kontext-dev 와 Qwen-Image-Edit 모두 이미지 생성 및 편집에 강력한 성능을 가지고 있는 모델입니다.그만큼 모델 크기도 굉장히 큽니다.FLUX.1-Kontext-dev는 약 120억개, Qwen-Image-Edit은 약 200억개에 달하는 파라미터 수를 가지고 있는데요. 그래서 rtx3090 GPU에서 실행하기에는 메모리가 많이 모자랍니다. import osfrom PIL import Imageimport torchfrom diffusers import QwenImageEditPipelinepipeline = QwenImageEditPipeline.from_pretrained("Qwen/Qwen-Image-Edit")print("pipeline loaded")pipel..