Record & Share Like a Pro
Free Screen Recording Tool
Made with ❤️ by developers at Codersera, forever free
2 min to read
DeepSeek Janus Pro 1B is a cutting-edge multimodal model capable of text-to-image generation and text understanding. This guide walks you through setting it up on Hugging Face and leveraging its advanced capabilities.
pip
installed.Install core dependencies via pip:
pip install transformers torch accelerate diffusers # Base libraries
pip install -U datasets huggingface_hub # Optional for data handling
For example scripts and custom utilities, clone the DeepSeek repository:
git clone https://github.com/deepseek-ai/Janus.git
cd Janus && pip install -r requirements.txt # Install model-specific dependencies
Use the MultiModalityCausalLM
class for multimodal tasks:
from transformers import AutoProcessor, MultiModalityCausalLM
# Load model and processor
processor = AutoProcessor.from_pretrained("deepseek-ai/Janus-Pro-1B")
model = MultiModalityCausalLM.from_pretrained(
"deepseek-ai/Janus-Pro-1B",
device_map="auto", # Auto-detects GPU/CPU
torch_dtype="auto" # Optimizes precision (float16/32)
)
# Generate an image from text
prompt = "A futuristic cityscape at sunset"
inputs = processor(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs)
# Save the generated image
outputs.images[0].save("cityscape.png")
For text-only tasks, use the standard text-generation pipeline:
from transformers import pipeline
pipe = pipeline("text-generation", model="deepseek-ai/Janus-Pro-1B")
response = pipe("Explain quantum computing simply:", max_length=200, temperature=0.7)
print(response[0]['generated_text'])
Run Janus Pro 1B in-browser using Transformers.js
:
import { AutoProcessor, MultiModalityCausalLM } from '@xenova/transformers';
const model = await MultiModalityCausalLM.from_pretrained("deepseek-ai/Janus-Pro-1B");
const processor = await AutoProcessor.from_pretrained(model);
// Generate images/text directly in the browser
Reduce VRAM usage with 4-bit quantization:
from transformers import BitsAndBytesConfig
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4"
)
model = MultiModalityCausalLM.from_pretrained(
"deepseek-ai/Janus-Pro-1B",
quantization_config=bnb_config
)
Issue | Solution |
---|---|
CUDA Out of Memory | Use fp16 or 4-bit quantization. |
Slow Inference | Enable device_map="auto" and torch.compile(model) . |
Model Not Found | Ensure you’re logged into Hugging Face: huggingface-cli login . |
processor(images=..., text=...)
for image-to-text tasks (e.g., captioning).temperature
(0.1–1.0) to balance creativity vs. determinism.For further assistance or updates:
By following these detailed steps, you should be able to successfully install and run DeepSeek Janus-Pro 1B on Hugging Face!