[{"data":1,"prerenderedAt":235},["ShallowReactive",2],{"content-query-EhCmuuKgHu":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"category":13,"body":14,"_type":229,"_id":230,"_source":231,"_file":232,"_stem":233,"_extension":234},"/technology-blogs/zh/3636","zh",false,"","基于昇思+昇腾，玩转 CogView4生成汉字！","如何基于昇思MindSpore和单机Atlas 800T A2，通过简单命令，单卡玩转 CogView4 推理。","2025-03-07","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/03/26/642cee8d2668420fa8a651bc45024dba.png","technology-blogs","实践",{"type":15,"children":16,"toc":226},"root",[17,25,31,36,41,52,57,66,76,90,99,107,114,147,155,165,173,178,186,191,199,206,214,221],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"基于昇思昇腾玩转-cogview4生成汉字",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":24,"value":30},"2025年3月4日，智谱开源了首个支持生成汉字的开源文生图模型 CogView4。该模型具有6B权重，支持原生中文输入，支持中文文字绘画。CogView4 在 DPG-Bench 基准测试中的综合评分排名第一，在开源文生图模型中达到 SOTA 水平。",{"type":18,"tag":26,"props":32,"children":33},{},[34],{"type":24,"value":35},"昇思MindSpore 团队快速支持 CogView4 Diffusers 工作流并开源至MindSpore ONE仓库，结合昇腾硬件，为开发者提供简单易用体验。本文将介绍如何基于昇思MindSpore和单机Atlas 800T A2，通过简单命令，单卡玩转 CogView4 推理。",{"type":18,"tag":26,"props":37,"children":38},{},[39],{"type":24,"value":40},"开源链接：",{"type":18,"tag":26,"props":42,"children":43},{},[44],{"type":18,"tag":45,"props":46,"children":50},"a",{"href":47,"rel":48},"https://github.com/mindspore-lab/mindone/tree/master/examples/cogview",[49],"nofollow",[51],{"type":24,"value":47},{"type":18,"tag":26,"props":53,"children":54},{},[55],{"type":24,"value":56},"魔乐社区在线体验：",{"type":18,"tag":26,"props":58,"children":59},{},[60],{"type":18,"tag":45,"props":61,"children":64},{"href":62,"rel":63},"https://modelers.cn/spaces/MindSpore-Lab/cogview4",[49],[65],{"type":24,"value":62},{"type":18,"tag":19,"props":67,"children":69},{"id":68},"_01效果展示",[70],{"type":18,"tag":71,"props":72,"children":73},"strong",{},[74],{"type":24,"value":75},"# 01****效果展示",{"type":18,"tag":26,"props":77,"children":78},{},[79,84,86],{"type":18,"tag":80,"props":81,"children":83},"img",{"alt":7,"src":82},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/03/14/f1d0702777464d23a78538010979e88d.png",[],{"type":24,"value":85}," ",{"type":18,"tag":80,"props":87,"children":89},{"alt":7,"src":88},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/03/14/7349dd33b9824a6ebc9f76a6d2da49f6.png",[],{"type":18,"tag":19,"props":91,"children":93},{"id":92},"_02快速玩转cogview4",[94],{"type":18,"tag":71,"props":95,"children":96},{},[97],{"type":24,"value":98},"# 02****快速玩转CogView4",{"type":18,"tag":26,"props":100,"children":101},{},[102],{"type":18,"tag":71,"props":103,"children":104},{},[105],{"type":24,"value":106},"1、环境准备",{"type":18,"tag":26,"props":108,"children":109},{},[110],{"type":18,"tag":80,"props":111,"children":113},{"alt":7,"src":112},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/03/14/acd638618b894074a0b7f0cb54c02bf2.png",[],{"type":18,"tag":115,"props":116,"children":117},"ul",{},[118,124,133,138],{"type":18,"tag":119,"props":120,"children":121},"li",{},[122],{"type":24,"value":123},"CANN下载：",{"type":18,"tag":119,"props":125,"children":126},{},[127],{"type":18,"tag":45,"props":128,"children":131},{"href":129,"rel":130},"https://www.hiascend.com/developer/download/community/result",[49],[132],{"type":24,"value":129},{"type":18,"tag":119,"props":134,"children":135},{},[136],{"type":24,"value":137},"MindSpore下载：",{"type":18,"tag":119,"props":139,"children":140},{},[141],{"type":18,"tag":45,"props":142,"children":145},{"href":143,"rel":144},"https://www.mindspore.cn/install",[49],[146],{"type":24,"value":143},{"type":18,"tag":26,"props":148,"children":149},{},[150],{"type":18,"tag":71,"props":151,"children":152},{},[153],{"type":24,"value":154},"2、安装依赖",{"type":18,"tag":156,"props":157,"children":159},"pre",{"code":158},"git clone https://github.com/mindspore-lab/mindone\n\n# install mindone\ncd mindone\npip install -e .\n\ncd examples/cogview\n",[160],{"type":18,"tag":161,"props":162,"children":163},"code",{"__ignoreMap":7},[164],{"type":24,"value":158},{"type":18,"tag":26,"props":166,"children":167},{},[168],{"type":18,"tag":71,"props":169,"children":170},{},[171],{"type":24,"value":172},"3、启动推理",{"type":18,"tag":26,"props":174,"children":175},{},[176],{"type":24,"value":177},"无需提前准备模型权重，Diffusers 工作流根据脚本给定的模型名称自动从 huggingface 获取权重！以下单行命令即可快速启动推理！",{"type":18,"tag":156,"props":179,"children":181},{"code":180},"python inference/cli_demo_cogview4.py --prompt {your prompt}\n",[182],{"type":18,"tag":161,"props":183,"children":184},{"__ignoreMap":7},[185],{"type":24,"value":180},{"type":18,"tag":26,"props":187,"children":188},{},[189],{"type":24,"value":190},"详细推理命令可参考以下样例。可使用 BF16 推理。",{"type":18,"tag":156,"props":192,"children":194},{"code":193},"from mindone.diffusers import CogView4Pipeline\nimport mindspore as ms\n\npipe = CogView4Pipeline.from_pretrained(\"THUDM/CogView4-6B\", mindspore_dtype=ms.bfloat16)\n\npipe.vae.enable_slicing()\npipe.vae.enable_tiling()\n\nprompt = \"A vibrant cherry red sports car sits proudly under the gleaming sun, its polished exterior smooth and flawless, casting a mirror-like reflection. The car features a low, aerodynamic body, angular headlights that gaze forward like predatory eyes, and a set of black, high-gloss racing rims that contrast starkly with the red. A subtle hint of chrome embellishes the grille and exhaust, while the tinted windows suggest a luxurious and private interior. The scene conveys a sense of speed and elegance, the car appearing as if it's about to burst into a sprint along a coastal road, with the ocean's azure waves crashing in the background.\"\nimage = pipe(\n    prompt=prompt,\n    guidance_scale=3.5,\n    num_images_per_prompt=1,\n    num_inference_steps=50,\n    width=1024,\n    height=1024,\n)[0][0]\n\nimage.save(\"cogview4.png\")\n",[195],{"type":18,"tag":161,"props":196,"children":197},{"__ignoreMap":7},[198],{"type":24,"value":193},{"type":18,"tag":26,"props":200,"children":201},{},[202],{"type":18,"tag":80,"props":203,"children":205},{"alt":7,"src":204},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/03/14/46789f1c8fd043d298dc383e21c1a71a.png",[],{"type":18,"tag":26,"props":207,"children":208},{},[209],{"type":18,"tag":71,"props":210,"children":211},{},[212],{"type":24,"value":213},"4、性能实测",{"type":18,"tag":26,"props":215,"children":216},{},[217],{"type":18,"tag":80,"props":218,"children":220},{"alt":7,"src":219},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/03/14/3d1bfd2173f144b18c9210dc1dbe71c4.png",[],{"type":18,"tag":26,"props":222,"children":223},{},[224],{"type":24,"value":225},"快来体验吧！",{"title":7,"searchDepth":227,"depth":227,"links":228},4,[],"markdown","content:technology-blogs:zh:3636.md","content","technology-blogs/zh/3636.md","technology-blogs/zh/3636","md",1776506132577]