mirror of
https://github.com/deepseek-ai/Janus.git
synced 2025-04-19 10:09:00 -04:00
Merge eb441468d8
into 1daa72fa40
This commit is contained in:
commit
3644b7ecd4
3
.gitignore
vendored
3
.gitignore
vendored
@ -419,3 +419,6 @@ tags
|
|||||||
.vscode
|
.vscode
|
||||||
.github
|
.github
|
||||||
generated_samples/
|
generated_samples/
|
||||||
|
|
||||||
|
# gradio
|
||||||
|
.gradio/
|
@ -19,7 +19,7 @@ vl_gpt = vl_gpt.to(torch.bfloat16).cuda()
|
|||||||
|
|
||||||
vl_chat_processor = VLChatProcessor.from_pretrained(model_path)
|
vl_chat_processor = VLChatProcessor.from_pretrained(model_path)
|
||||||
tokenizer = vl_chat_processor.tokenizer
|
tokenizer = vl_chat_processor.tokenizer
|
||||||
cuda_device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
cuda_device = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'
|
||||||
# Multimodal Understanding function
|
# Multimodal Understanding function
|
||||||
@torch.inference_mode()
|
@torch.inference_mode()
|
||||||
# Multimodal Understanding function
|
# Multimodal Understanding function
|
||||||
|
@ -5,7 +5,13 @@ from PIL import Image
|
|||||||
from diffusers.models import AutoencoderKL
|
from diffusers.models import AutoencoderKL
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
cuda_device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
cuda_device = 'cpu'
|
||||||
|
if torch.cuda.is_available():
|
||||||
|
cuda_device = 'cuda'
|
||||||
|
elif torch.backends.mps.is_available():
|
||||||
|
cuda_device = 'mps'
|
||||||
|
else:
|
||||||
|
cuda_device = 'cpu'
|
||||||
|
|
||||||
# Load model and processor
|
# Load model and processor
|
||||||
model_path = "deepseek-ai/JanusFlow-1.3B"
|
model_path = "deepseek-ai/JanusFlow-1.3B"
|
||||||
|
@ -21,23 +21,29 @@ vl_gpt = AutoModelForCausalLM.from_pretrained(model_path,
|
|||||||
trust_remote_code=True)
|
trust_remote_code=True)
|
||||||
if torch.cuda.is_available():
|
if torch.cuda.is_available():
|
||||||
vl_gpt = vl_gpt.to(torch.bfloat16).cuda()
|
vl_gpt = vl_gpt.to(torch.bfloat16).cuda()
|
||||||
|
cuda_device = 'cuda'
|
||||||
|
elif torch.backends.mps.is_available():
|
||||||
|
vl_gpt = vl_gpt.to(torch.float16).to('mps')
|
||||||
|
cuda_device = 'mps'
|
||||||
else:
|
else:
|
||||||
vl_gpt = vl_gpt.to(torch.float16)
|
vl_gpt = vl_gpt.to(torch.float16)
|
||||||
|
cuda_device = 'cpu'
|
||||||
|
|
||||||
vl_chat_processor = VLChatProcessor.from_pretrained(model_path)
|
vl_chat_processor = VLChatProcessor.from_pretrained(model_path)
|
||||||
tokenizer = vl_chat_processor.tokenizer
|
tokenizer = vl_chat_processor.tokenizer
|
||||||
cuda_device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
||||||
|
|
||||||
@torch.inference_mode()
|
@torch.inference_mode()
|
||||||
# @spaces.GPU(duration=120)
|
# @spaces.GPU(duration=120)
|
||||||
# Multimodal Understanding function
|
# Multimodal Understanding function
|
||||||
def multimodal_understanding(image, question, seed, top_p, temperature):
|
def multimodal_understanding(image, question, seed, top_p, temperature):
|
||||||
# Clear CUDA cache before generating
|
# Clear CUDA cache before generating
|
||||||
|
if torch.cuda.is_available():
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
|
|
||||||
# set seed
|
# set seed
|
||||||
torch.manual_seed(seed)
|
torch.manual_seed(seed)
|
||||||
np.random.seed(seed)
|
np.random.seed(seed)
|
||||||
|
if torch.cuda.is_available():
|
||||||
torch.cuda.manual_seed(seed)
|
torch.cuda.manual_seed(seed)
|
||||||
|
|
||||||
conversation = [
|
conversation = [
|
||||||
@ -83,6 +89,7 @@ def generate(input_ids,
|
|||||||
image_token_num_per_image: int = 576,
|
image_token_num_per_image: int = 576,
|
||||||
patch_size: int = 16):
|
patch_size: int = 16):
|
||||||
# Clear CUDA cache before generating
|
# Clear CUDA cache before generating
|
||||||
|
if torch.cuda.is_available():
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
|
|
||||||
tokens = torch.zeros((parallel_size * 2, len(input_ids)), dtype=torch.int).to(cuda_device)
|
tokens = torch.zeros((parallel_size * 2, len(input_ids)), dtype=torch.int).to(cuda_device)
|
||||||
@ -138,10 +145,12 @@ def generate_image(prompt,
|
|||||||
guidance=5,
|
guidance=5,
|
||||||
t2i_temperature=1.0):
|
t2i_temperature=1.0):
|
||||||
# Clear CUDA cache and avoid tracking gradients
|
# Clear CUDA cache and avoid tracking gradients
|
||||||
|
if torch.cuda.is_available():
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
# Set the seed for reproducible results
|
# Set the seed for reproducible results
|
||||||
if seed is not None:
|
if seed is not None:
|
||||||
torch.manual_seed(seed)
|
torch.manual_seed(seed)
|
||||||
|
if torch.cuda.is_available():
|
||||||
torch.cuda.manual_seed(seed)
|
torch.cuda.manual_seed(seed)
|
||||||
np.random.seed(seed)
|
np.random.seed(seed)
|
||||||
width = 384
|
width = 384
|
||||||
|
@ -21,7 +21,7 @@ vl_gpt = vl_gpt.to(torch.bfloat16).cuda()
|
|||||||
|
|
||||||
vl_chat_processor = VLChatProcessor.from_pretrained(model_path)
|
vl_chat_processor = VLChatProcessor.from_pretrained(model_path)
|
||||||
tokenizer = vl_chat_processor.tokenizer
|
tokenizer = vl_chat_processor.tokenizer
|
||||||
cuda_device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
cuda_device = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'
|
||||||
|
|
||||||
|
|
||||||
@torch.inference_mode()
|
@torch.inference_mode()
|
||||||
|
Loading…
Reference in New Issue
Block a user