NVIDIA RTX PC 开源 AI 工具升级:加速 LLM 与扩散模型性能
在人工智能快速发展的今天,PC 端的 AI 开发活动正在经历爆炸式增长。小型语言模型(SLMs)和扩散模型质量的显著提升,如 FLUX.2、GPT-OSS-20B 和 Nemotron 3 Nano 等模型的出现,推动了这一趋势。ComfyUI、llama.cpp、Ollama 和 Unsloth 等 AI PC 框架也在不断进行功能升级。
一、ComfyUI 的持续性能改进:扩散模型加速的新里程碑
ComfyUI 作为扩散模型领域最受欢迎的开源框架之一,在 NVIDIA 的协作下实现了显著的性能突破。通过 PyTorch-CUDA 的深度优化,ComfyUI 现已支持 NVFP4 和 FP8 量化格式,这些量化格式分别实现了 60% 和 40% 的显存节省,同时大幅提升了推理性能。
1.1 ComfyUI 核心优化特性详解
NVFP4 支持:线性层可以使用 NVFP4 格式运行,配合优化的内核实现,相比 FP16 和 BF16 线性层可提供 3-4 倍的吞吐量提升。
融合 FP8 量化/反量化内核:通过消除内存带宽受限的操作,这些融合内核显著提升了模型性能。
权重流式传输:利用并发的系统内存和 CPU 计算流,权重流式传输技术可以隐藏内存延迟并提高吞吐量,特别适合 VRAM 有限的 GPU。
混合精度支持:模型可以在单个网络中组合多种数值格式,实现精细化调优以获得最佳的准确性和性能平衡。
1.2 ComfyUI NVFP4 量化工作流代码示例
import torch
import comfy.model_management as mm
from comfy.sd import load_checkpoint_guess_config
import comfy.utils
# 配置 NVFP4 量化参数
quantization_config = {
'enable_nvfp4': True,
'nvfp4_linear_only': True,
'fallback_dtype': torch.float16
}
# 加载预训练的扩散模型检查点
checkpoint_path = "/path/to/flux2_nvfp4.safetensors"
model, clip, vae, clip_vision = load_checkpoint_guess_config(
checkpoint_path,
output_vae=True,
output_clip=True,
quantization=quantization_config
)
device = mm.get_torch_device()
model.to(device)
model.eval()
prompt_text = "A futuristic cityscape at sunset with flying cars"
tokens = clip.tokenize(prompt_text)
cond, pooled = clip.encode_from_tokens(tokens, return_pooled=)
sampling_params = {
: ,
: ,
: ,
: ,
:
}
latent_image = torch.randn(, , , , device=device, dtype=torch.float16)
torch.inference_mode():
samples = comfy.sample.sample(
model, noise=latent_image, positive=cond, negative=,
cfg=sampling_params[], steps=sampling_params[],
sampler_name=sampling_params[]
)
decoded_images = vae.decode(samples)
images = (decoded_images + ) /
images = torch.clamp(images, , )
images = (images * ).to(torch.uint8)
PIL Image
numpy np
i, img_tensor (images):
img_np = img_tensor.permute(, , ).cpu().numpy()
img_pil = Image.fromarray(img_np)
img_pil.save()


