SmolDocling-256M 安装

环境部署

pip install  torch transformers docling_core -i https://mirrors.aliyun.com/pypi/simple/

下载 hf-mirror镜像(默认例子会自动下载)

pip install transformers numpy huggingface_hub -i https://mirrors.aliyun.com/pypi/simple/

export HF_ENDPOINT=https://hf-mirror.com

huggingface-cli download ds4sd/SmolDocling-256M-preview --local-dir SmolDoclin-256M

官方示例 (会自动从huggingface下载模型)

# Prerequisites:
# pip install torch
# pip install docling_core
# pip install transformers

import torch
from docling_core.types.doc import DoclingDocument
from docling_core.types.doc.document import DocTagsDocument
from transformers import AutoProcessor, AutoModelForVision2Seq
from transformers.image_utils import load_image
from pathlib import Path

DEVICE = "cuda" if torch.cuda.is_available() else "cpu"

# Load images
image = load_image("https://upload.wikimedia.org/wikipedia/commons/7/76/GazettedeFrance.jpg")

# Initialize processor and model
processor = AutoProcessor.from_pretrained("ds4sd/SmolDocling-256M-preview")
model = AutoModelForVision2Seq.from_pretrained(
    "ds4sd/SmolDocling-256M-preview",
    torch_dtype=torch.bfloat16,
    _attn_implementation="flash_attention_2" if DEVICE == "cuda" else "eager",
).to(DEVICE)

# Create input messages
messages = [
    {
        "role": "user",
        "content": [
            {"type": "image"},
            {"type": "text", "text": "Convert this page to docling."}
        ]
    },
]

# Prepare inputs
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(text=prompt, images=[image], return_tensors="pt")
inputs = inputs.to(DEVICE)

# Generate outputs
generated_ids = model.generate(**inputs, max_new_tokens=8192)
prompt_length = inputs.input_ids.shape[1]
trimmed_generated_ids = generated_ids[:, prompt_length:]
doctags = processor.batch_decode(
    trimmed_generated_ids,
    skip_special_tokens=False,
)[0].lstrip()

# Populate document
doctags_doc = DocTagsDocument.from_doctags_and_image_pairs([doctags], [image])
print(doctags)
# create a docling document
doc = DoclingDocument(name="Document")
doc.load_from_doctags(doctags_doc)

# export as any format
# HTML
# Path("Out/").mkdir(parents=True, exist_ok=True)
# output_path_html = Path("Out/") / "example.html"
# doc.save_as_html(output_path_html)
# MD
print(doc.export_to_markdown())

RAGFlow安装

1.Docker 与 Docker-compose安装

docker安装

sudo apt update && sudo apt install docker.io apparmor -y

docker-compose安装

sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

测试:docker-compose

RAGFlow下载

git clone https://github.com/infiniflow/ragflow.git

cd ragflow/docker

安装RAGflow

docker-compose -f docker-compose.yml up -d

直接通过命令 docker ps 查看信息;

浏览器访问 http://IP 即可进入

RAG 搭建 anythingllm 建议E5v2之前不要尝试 包括V2

angthingllm 可以本地桌面和搭建服务器web端。

下面是WEB端的搭建(需要DOCKER):
Ubuntu下Docker sudo apt update && sudo apt install docker.io apparmor -y

anythingLLM 的Docker部署命令:

export STORAGE_LOCATION=$HOME/anythingllm && \
mkdir -p $STORAGE_LOCATION && \
touch "$STORAGE_LOCATION/.env" && \
docker run -d -p 3001:3001 \
--cap-add SYS_ADMIN \
-v ${STORAGE_LOCATION}:/app/server/storage \
-v ${STORAGE_LOCATION}/.env:/app/server/.env \
-e STORAGE_DIR="/app/server/storage" \
mintplexlabs/anythingllm

访问你的http://IP:3001 即可

坑点:

E5 V2 CPU 不支持 会在首页设置模型处报错,docker直接下线。

vultr 新建4C 8G 可以运行

需要给anythingllm目录整体给予777 权限 即可,下面步骤:

  • 1.即先docker运行失败,后再加入执行
  • 2.chmod -R 777 anythingllm
  • 3.再执行docker命令启动

docker logs报错/usr/local/bin/docker-entrypoint.sh: line 7:   105 Illegal instruction     (core dumped) node /app/server/index.js

在网页设置中 无法进入下一步,网页显示报错
Failed to save LLM settings: Failed to fetch

在默认设置的目录需要写入权限 直接777 完事 chmod -R 777 $HOME/anythingllm

MAC上部署Wan2.1 1.3b生成视频模型安装 ERROR 250312

flash-attention 只能X86下CUDA。apple的MPS 无法安装!!!

撤退!

主要是 :下载代码库,安装依赖,下载模型,调用即可。

  1. GIT上下载Wan2.1 git clone https://github.com/Wan-Video/Wan2.1.git
  2. 进入刚刚下载的wan2.1的目录,在其中安装 pip install -r requirements.txt 其中注意flash-attention的安装;使用清华源安装 pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
  3. 执行修改为hf-mirror的镜像:export HF_ENDPOINT=https://hf-mirror.com;hf-mirror上下载 Wan-AI/Wan2.1-T2V-1.3B huggingface-cli download Wan-AI/Wan2.1-T2V-1.3B --local-dir ./Wan2.1-T2V-1.3B
  4. 进入GIT下载的wan2.1目录进行测试。python generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."

1.3B只能txt,不能图片转视频且只能最高480P。14B可以指出图片转视频最高720P。

下面来自wan2.1的官方部署信息。

 Installation
Clone the repo:
git clone https://github.com/Wan-Video/Wan2.1.git cd Wan2.1
Install dependencies:
# Ensure torch >= 2.4.0 pip install -r requirements.txt
 Model Download
Models
Download Link
Notes
T2V-14B
🤗 Huggingface 🤖 ModelScope
Supports both 480P and 720P
I2V-14B-720P
🤗 Huggingface 🤖 ModelScope
Supports 720P
I2V-14B-480P
🤗 Huggingface 🤖 ModelScope
Supports 480P
T2V-1.3B
🤗 Huggingface 🤖 ModelScope
Supports 480P
💡Note: The 1.3B model is capable of generating videos at 720P resolution. However, due to limited training at this resolution, the results are generally less stable compared to 480P. For optimal performance, we recommend using 480P resolution.
Download models using 🤗 huggingface-cli:
pip install "huggingface_hub[cli]" huggingface-cli download Wan-AI/Wan2.1-T2V-1.3B --local-dir ./Wan2.1-T2V-1.3B
Download models using 🤖 modelscope-cli:
pip install modelscope modelscope download Wan-AI/Wan2.1-T2V-1.3B --local_dir ./Wan2.1-T2V-1.3B
 Run Text-to-Video Generation
This repository supports two Text-to-Video models (1.3B and 14B) and two resolutions (480P and 720P). The parameters and configurations for these models are as follows:
Task
Resolution
Model
480P
720P
t2v-14B
✔️
✔️
Wan2.1-T2V-14B
t2v-1.3B
✔️

Wan2.1-T2V-1.3B
 (1) Without Prompt Extention
To facilitate implementation, we will start with a basic version of the inference process that skips the prompt extension step.
Single-GPU inference
python generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --sample_shift 8 --sample_guide_scale 6 --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."
If you encounter OOM (Out-of-Memory) issues, you can use the --offload_model True and --t5_cpu options to reduce GPU memory usage. For example, on an RTX 4090 GPU:
python generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --offload_model True --t5_cpu --sample_shift 8 --sample_guide_scale 6 --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."
💡Note: If you are using the T2V-1.3B model, we recommend setting the parameter --sample_guide_scale 6. The --sample_shift parameter can be adjusted within the range of 8 to 12 based on the performance.
Multi-GPU inference using FSDP + xDiT USP
pip install "xfuser>=0.4.1" torchrun --nproc_per_node=8 generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --dit_fsdp --t5_fsdp --ulysses_size 8 --sample_shift 8 --sample_guide_scale 6 --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."

利息计算

每个类型的利息计算单独自拿出来,1。传入数据自动计算再返回数据

计算第一期利息 月度和季度有问题;第一期计算;执行start开始日期小于合同开始日期为第一期,则开始日期修改为合同开始日期。

最后一期,当合同结束日期,小于end日期,则结束日期修改为合同结束日期。

提前结束合同,会有个值出现时提前结束合同,相当于合同结束日期。

合同结束日期:如果合同提前结束日期出现,那么合同结束日期就改为合同提前结束日期。

每期利息都计入数据表;利率 、开始日期 、结束日期 、天数、 剩余本金 、贷款ID。