云服务器部署DeepSeek Janus-Pro生成图片实战

本文主要研究一下如何在腾讯云HAI-GPU服务器上部署DeepSeek Janus-Pro来进行文本生成图片

步骤

选择带GPU的服务器

deepseek2025试用一下带GPU的服务器

下载Janus

git clone https://github.com/deepseek-ai/Janus.git

安装依赖

cd Janus
pip install -e .

安装gradio

pip install gradio

安装torch

pip uninstall torch torchvision torchaudio -y
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

运行示例

python demo/app_januspro.py --device cuda

输出示例如下

Python version is above 3.10, patching the collections module.
/root/miniforge3/lib/python3.10/site-packages/transformers/models/auto/image_processing_auto.py:594: FutureWarning: The image_processor_class argument is deprecated and will be removed in v4.42. Please use `slow_image_processor_class`, or `fast_image_processor_class` instead
  warnings.warn(
pytorch_model-00001-of-00002.bin: 100%|███████████████████████████████████████████████████████████████████████████████████████████| 9.99G/9.99G [09:34<00:00, 11.9MB/s]
pytorch_model-00002-of-00002.bin: 100%|███████████████████████████████████████████████████████████████████████████████████████████| 4.85G/4.85G [06:46<00:00, 11.9MB/s]
Downloading shards: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [16:21<00:00, 490.70s/it]
Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:04<00:00,  2.47s/it]
preprocessor_config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 346/346 [00:00<00:00, 3.40MB/s]
Using a slow image processor as `use_fast` is unset and a slow processor was saved with this model. `use_fast=True` will be the default behavior in v4.48, even if the model was saved with a slow processor. This will result in minor differences in outputs. You'll still be able to use a slow processor with `use_fast=False`.
tokenizer_config.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 285/285 [00:00<00:00, 2.94MB/s]
tokenizer.json: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4.72M/4.72M [00:00<00:00, 18.1MB/s]
special_tokens_map.json: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 344/344 [00:00<00:00, 2.93MB/s]
You are using the default legacy behaviour of the <class 'transformers.models.llama.tokenization_llama_fast.LlamaTokenizerFast'>. This is expected, and simply means that the `legacy` (previous) behavior will be used so nothing changes for you. If you want to use the new behaviour, set `legacy=False`. This should only be set if you understand what it means, and thoroughly read the reason why this was added as explained in https://github.com/huggingface/transformers/pull/24565 - if you loaded a llama tokenizer from a GGUF file you can ignore this message.
processor_config.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 210/210 [00:00<00:00, 2.00MB/s]
Some kwargs in processor config are unused and will not have any effect: ignore_id, add_special_token, num_image_tokens, mask_prompt, sft_format, image_tag. 
* Running on local URL:  http://127.0.0.1:7860
* Running on public URL: https://xxxxx.gradio.live

This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)

可以访问这个public URL

使用示例

在这里插入图片描述

大概需要等120s左右可以生成,app.py使用的模型deepseek-ai/Janus-1.3B

小结

自己部署实际还是挺多麻烦的(最开始是在mac上跑,遇到CUDA_HOME问题,后来是找了cpu版本的,遇到没有GPU的问题,最后用了一个带GPU的服务器才跑成功),会遇到各种依赖问题,还有GPU等配置问题,另外就是网络访问问题,所以实际折腾下来就是,如果没有其他特殊需求,还是乖乖用云服务的api吧。

doc

### DeepSeek Janus-Pro 本地部署教程 为了在本地环境中成功部署 DeepSeekJanus-Pro 模型,需遵循官方提供的具体步骤。首先,获取项目源码是必要的前置操作: 通过 Git 将 `Janus` 仓库克隆至本地环境以便于后续配置与开发工作开展。 ```bash git clone https://github.com/deepseek-ai/Janus.git cd Janus ``` 完成上述命令执行之后,进入到了项目的根目录下,在这里可以找到有关如何设置运行环境以及加载预训练模型的相关文档和支持文件[^1]。 接着,按照官方说明准备所需的依赖项和环境变量,这通常涉及到安装 Python 虚拟环境、pip 工具以及其他可能必需的软件包来满足特定版本的要求。对于更详细的指导,请参阅 GitHub 上该项目页面中的 README 文件或其他辅助资料[^2]。 最后一步则是下载并加载所选大小(如7B参数量级)的预训练权重文件到指定位置,并确保一切正常运作。可以通过访问 Hugging Face 平台上的对应存储库链接来进行这一过程;例如针对较大规模版本可参照如下地址:<https://huggingface.co/deepseek-ai/Janus-Pro-7B> 来获取更多信息。 #### 示例代码片段展示如何初始化已下载好的模型实例: ```python from transformers import AutoModelForCausalLM, AutoTokenizer model_name_or_path = "path_to_downloaded_model" tokenizer = AutoTokenizer.from_pretrained(model_name_or_path) model = AutoModelForCausalLM.from_pretrained(model_name_or_path) text = "Some input text here." inputs = tokenizer(text, return_tensors="pt") outputs = model.generate(**inputs) result = tokenizer.decode(outputs[0], skip_special_tokens=True) print(result) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值