add ops
This commit is contained in:
20
torch_mlu_ops-v1.3.2/docs/user_guide/Makefile
Normal file
20
torch_mlu_ops-v1.3.2/docs/user_guide/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
# Minimal makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
SPHINXPROJ = torch_mlu_ops_rst
|
||||
SOURCEDIR = source
|
||||
BUILDDIR = build
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
.PHONY: help Makefile
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
90
torch_mlu_ops-v1.3.2/docs/user_guide/README.rst
Normal file
90
torch_mlu_ops-v1.3.2/docs/user_guide/README.rst
Normal file
@@ -0,0 +1,90 @@
|
||||
使用说明
|
||||
=============================
|
||||
|
||||
重要文件及文件夹说明
|
||||
-----------------------------
|
||||
|
||||
**注意:**
|
||||
|
||||
工程下载后的所有内容,都不能删除,否则会造成工程编译失败。
|
||||
|
||||
* source文件夹:保存rst源文件。所有新增的rst文件及文件夹务必都保存在source文件夹中,否则生成的文件将不包含新增内容。
|
||||
* build文件夹:保存构建后的文件,该文件在执行make html和./makelatexpdf.sh后会自动生成。build及其子文件夹都是构建后自动生成,所以无需关注。
|
||||
|
||||
- 执行make html生成html文件,保存在“build/html”文件夹中。
|
||||
- 执行./makelatexpdf.sh生成latex和pdf文件,保存在“build/latex”文件夹中。
|
||||
|
||||
* makelatexpdf.sh:核心编译脚本,生成latex和pdf文件。
|
||||
|
||||
**注意:**
|
||||
|
||||
下载工程后,请执行“chmod +x makelatexpdf.sh”命令修改该文件的权限,否则脚本无法执行。
|
||||
|
||||
* source/index.rst:核心索引文件,sphinx依据该文件生成文件的大纲目录。所有新增的rst文件都要添加到该文件中,否则生成的文档中将不包含新增内容。
|
||||
|
||||
文档写作约束
|
||||
--------------------------------
|
||||
|
||||
**rst语法参考网址** :http://www.pythondoc.com/sphinx/rest.html
|
||||
|
||||
rst文件为纯文本文件,因此可以使用vim、notepad++或者vscode等任何文本编辑器编写。其中vim天然支持rst,会对rst语法进行高亮显示。
|
||||
vscode可以通过下载插件的方式实现rst语法高亮和实时预览,但是vscode对rst表格的兼容性不是很好。
|
||||
|
||||
**注意:**
|
||||
|
||||
不管用哪种编辑器,都务必将tab设置为4个空格,否则格式可能会达不到预期,或者引入编译告警。尤其影响表格的编辑,因此务必将tab设置为4个空格。
|
||||
|
||||
* 文档编译服务器,工程可以下载到该服务器编写编译。目前只有该服务器搭建了文档编译环境,能够完成文档的编译。
|
||||
* 所有新增内容,都务必放在“source”文件夹下,不能放在其它文件夹,避免工程编译失败,达不到预期效果。
|
||||
* 一级大纲或者新建的独立模块建议新建文件夹,rst源文件都保存在新建文件夹下,以便工程有清晰的层级结构,方便维护。可以参考“preface”文件夹的构建。
|
||||
* 文件目录深度最多为4级,超过4级不方便用户阅读。4个级别大纲的标识按以下顺序:
|
||||
|
||||
1. 一级大纲标识:=;
|
||||
#. 二级大纲标识:-;
|
||||
#. 三级大纲标识:^;
|
||||
#. 四级大纲标识:~;
|
||||
|
||||
举例如下:
|
||||
|
||||
::
|
||||
|
||||
我是一级大纲举例
|
||||
========================
|
||||
我是二级大纲举例
|
||||
------------------------
|
||||
我是三级大纲举例
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
我是四级大纲举例
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
使用举例
|
||||
----------------------------------------
|
||||
|
||||
以新建“前言”章节为例,举例说明如何新增内容,新增内容后,如何编译生成html和pdf文件。下载的工程中“前言”章节已经添加完成,可以参考。
|
||||
|
||||
* 步骤一:通过ssh登陆文档编译服务器。
|
||||
* 步骤二:在Torch-MLU-Ops仓库下载user_guide文件夹及其内容。
|
||||
* 步骤三:执行命令“chmod +x makelatexpdf.sh”修改makelatexpdf.sh脚本的权限,避免无法编译。
|
||||
* 步骤四:在“source”文件夹下,新建“preface”文件,保存前言相关的rst文件。
|
||||
* 步骤五:在“preface”文件夹下,新建两个文件:preface.rst和index.rst。
|
||||
|
||||
- preface.rst:用来保存前言相关内容
|
||||
- index.rst:用来保存"preface"文件夹下所有rst文件的索引。
|
||||
|
||||
将preface.rst添加到index.rst。
|
||||
|
||||
**说明**
|
||||
|
||||
preface文件夹下新建index.rst是为了方便管理同一文件夹下的内容,这样在外层的主索引文件“index.rst”中只要添加该文件夹的index索引文件即可。
|
||||
|
||||
也可以不新建index.rst,将preface文件夹下的文件一一添加到外层的主索引文件“index.rst”中。为了方便管理建议每个文件夹下都新建index.rst统一管理该文件夹下的索引。
|
||||
|
||||
* 步骤六:按照rst语法和文档写作约束编写preface.rst”文件。
|
||||
* 步骤七:将“preface/index.rst”文件添加到外层的主索引文件“index.rst”中。
|
||||
* 步骤八:执行“./makelatexpdf.sh”脚本生成pdf文件,保存在“build/latex”文件夹下。执行“make html”命令生成html文件,保存在“build/html”文件夹下。
|
||||
|
||||
**注意:**
|
||||
|
||||
在执行“./makelatexpdf.sh”或者“make html”过程中,要注意sphinx红色字体的“WARNING"告警,务必将告警清除,否则可能无法生成文件或者生成的文件无法达到预期。
|
||||
|
||||
经过以上步骤,“前言”章节添加成功,可以查看最终生成的pdf和html文件,检查最终效果。
|
||||
1610
torch_mlu_ops-v1.3.2/docs/user_guide/_ext/customdirective.py
Normal file
1610
torch_mlu_ops-v1.3.2/docs/user_guide/_ext/customdirective.py
Normal file
File diff suppressed because it is too large
Load Diff
63
torch_mlu_ops-v1.3.2/docs/user_guide/_static/custom.css
Normal file
63
torch_mlu_ops-v1.3.2/docs/user_guide/_static/custom.css
Normal file
@@ -0,0 +1,63 @@
|
||||
@import url("theme.css");
|
||||
|
||||
.wy-nav-content {
|
||||
max-width: 100%;
|
||||
}
|
||||
pre.literal-block{
|
||||
background-color: #eeffcc;
|
||||
}
|
||||
.highlight .k{
|
||||
color: #404040;
|
||||
font-weight: 400;
|
||||
}
|
||||
a.reference.internal:after{
|
||||
content: " ";
|
||||
white-space: pre;
|
||||
}
|
||||
div.wy-menu.wy-menu-vertical{
|
||||
height:100%;
|
||||
overflow-y:auto;
|
||||
}
|
||||
.dldpdf-btn{
|
||||
position:fixed;
|
||||
top:20px;
|
||||
right:100px;
|
||||
background-color:#ff6c37;
|
||||
color:#ffffff;
|
||||
font-size:18px;
|
||||
font-weight:bold;
|
||||
padding:16px 30px;
|
||||
border-radius:50%;
|
||||
cursor:pointer;
|
||||
box-shadow: 0px 4px 10px 0px rgba(0,0,0,0.5);
|
||||
}
|
||||
.feedback-btn{
|
||||
position:fixed;
|
||||
right:5px;
|
||||
background-color:#1E90FF;
|
||||
color:#ffffff;
|
||||
width: 25px;
|
||||
border: 2px solid #FFEFD5;
|
||||
height: 90px;
|
||||
line-height: 20px;
|
||||
word-wrap: break-word;
|
||||
text-align: center;
|
||||
cursor:pointer;
|
||||
font-weight:bold;
|
||||
top:40%;
|
||||
box-shadow: 0px 4px 10px 0px rgba(0,0,0,0.5);
|
||||
}
|
||||
.showdiv{
|
||||
display: none;
|
||||
position:fixed;
|
||||
background-color: #ff6c37;
|
||||
color: #fff;
|
||||
top: 45%;
|
||||
right: 30px;
|
||||
padding: 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.doccenter{
|
||||
transform: translateX(5%);
|
||||
}
|
||||
BIN
torch_mlu_ops-v1.3.2/docs/user_guide/chapterbkpaper.pdf
Normal file
BIN
torch_mlu_ops-v1.3.2/docs/user_guide/chapterbkpaper.pdf
Normal file
Binary file not shown.
36
torch_mlu_ops-v1.3.2/docs/user_guide/make.bat
Normal file
36
torch_mlu_ops-v1.3.2/docs/user_guide/make.bat
Normal file
@@ -0,0 +1,36 @@
|
||||
@ECHO OFF
|
||||
|
||||
pushd %~dp0
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set SOURCEDIR=source
|
||||
set BUILDDIR=build
|
||||
set SPHINXPROJ=torch_mlu_ops_rst
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
%SPHINXBUILD% >NUL 2>NUL
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||
echo.may add the Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.http://sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
||||
goto end
|
||||
|
||||
:help
|
||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
||||
|
||||
:end
|
||||
popd
|
||||
5
torch_mlu_ops-v1.3.2/docs/user_guide/makelatexpdf.sh
Executable file
5
torch_mlu_ops-v1.3.2/docs/user_guide/makelatexpdf.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#! /bin/bash
|
||||
apt-get install -y dvipng
|
||||
make clean
|
||||
make latexpdf
|
||||
make html&&zip -qr -P"Cambricon" build/torch_mlu_ops_user_guide_html.zip build/html
|
||||
3552
torch_mlu_ops-v1.3.2/docs/user_guide/parsejson.py
Normal file
3552
torch_mlu_ops-v1.3.2/docs/user_guide/parsejson.py
Normal file
File diff suppressed because it is too large
Load Diff
6
torch_mlu_ops-v1.3.2/docs/user_guide/requirements.txt
Executable file
6
torch_mlu_ops-v1.3.2/docs/user_guide/requirements.txt
Executable file
@@ -0,0 +1,6 @@
|
||||
sphinx==3.3.1
|
||||
breathe==4.24.1
|
||||
sphinx_rtd_theme
|
||||
|
||||
jinja2==2.10.2
|
||||
markupsafe==1.1.1
|
||||
164
torch_mlu_ops-v1.3.2/docs/user_guide/source/conf.json
Normal file
164
torch_mlu_ops-v1.3.2/docs/user_guide/source/conf.json
Normal file
@@ -0,0 +1,164 @@
|
||||
{
|
||||
"package": [
|
||||
"\\\\usepackage{amsmath}",
|
||||
"\\\\usepackage[table]{xcolor}",
|
||||
"\\\\usepackage{eso-pic}",
|
||||
"\\\\usepackage{wallpaper}",
|
||||
"%\\\\usepackage{titlesec}",
|
||||
"\\\\usepackage{tocbibind}",
|
||||
"% \\\\usepackage{draftwatermark}",
|
||||
"\\\\usepackage{enumitem}",
|
||||
"\\\\usepackage{tcolorbox}",
|
||||
"\\\\usepackage{listings}",
|
||||
"\\\\usepackage{framed}",
|
||||
"\\\\usepackage{color}",
|
||||
"\\\\usepackage{multirow}",
|
||||
"% \\\\usepackage[justification=centering]{caption}"
|
||||
],
|
||||
"replacepackage": {
|
||||
"comment": "该章节内容是为了替换现有tex里面包的配置,左边为tex文件现有内容,右边是替换内容。",
|
||||
"\\\\usepackage{hyperref}": "\\\\usepackage[bookmarksnumbered=true]{hyperref}",
|
||||
"\\\\sphinxtableofcontents":
|
||||
"\\\\ThisURCornerWallPaper{1}{chapterbkpaper.pdf}\n\\\\sphinxtableofcontents",
|
||||
"\\\\chapter{([\\s\\S].*)}":
|
||||
"\\\\chapter{\\1}\n\\\\ThisURCornerWallPaper{1}{chapterbkpaper.pdf}",
|
||||
"\\\\listoffigures": "\\\\ThisURCornerWallPaper{1}{chapterbkpaper.pdf}\n\\\\listoffigures",
|
||||
"\\\\listoftables":
|
||||
"\\\\newpage\n\\\\ThisURCornerWallPaper{1}{chapterbkpaper.pdf}\n\\\\listoftables",
|
||||
"\\\\footnotesize\\\\raggedright\\\\printindex":
|
||||
"% \\\\footnotesize\\\\raggedright\\\\printindex",
|
||||
"\\\\begin{itemize}": "\\\\begin{itemize}[leftmargin=*]",
|
||||
"\\\\begin{enumerate}": "\\\\begin{enumerate}[leftmargin=*]",
|
||||
"\\\\setmainfont{FreeSerif}\\[[\\s\\S]*?\\]": "",
|
||||
"\\\\setsansfont{FreeSans}\\[[\\s\\S]*?\\]": "",
|
||||
"\\\\setmonofont{FreeMono}\\[[\\s\\S]*?\\]": "",
|
||||
"Extension([\\s\\S]*?)= .otf,": "Extension = ,",
|
||||
"\\\\sphinxtoprule": "\\\\hline",
|
||||
"\\\\sphinxmidrule": "\\\\hline",
|
||||
"\\\\sphinxbottomrule": "\\\\hline",
|
||||
"\\\\sphinxhline": "\\\\hline",
|
||||
"\\\\sphinxhyphen": "{sphinx:5.3.0}\\\\PYGZhy",
|
||||
"\\\\begin{sphinxalltt}": "\\\\begin{sphinxVerbatim}[commandchars=\\\\\\\\\\\\{\\}]",
|
||||
"\\\\end{sphinxalltt}": "\\\\end{sphinxVerbatim}",
|
||||
"\\\\begin{sphinxadmonition}{note}{注解:}":
|
||||
"\\\\begin{tcolorbox}[colframe={noteframecolor},colback={notebackcolor},coltitle=white,fonttitle=\\\\bfseries,title=注解:]",
|
||||
"\\\\begin{sphinxadmonition}{warning}{警告:}":
|
||||
"\\\\begin{tcolorbox}[colframe={warningframecolor},colback={warningbackcolor},coltitle=white,fonttitle=\\\\bfseries,title=警告:]",
|
||||
"\\\\begin{sphinxadmonition}{tip}{小技巧:}":
|
||||
"\\\\begin{tcolorbox}[colframe={noteframecolor},colback={notebackcolor},coltitle=white,fonttitle=\\\\bfseries,title=小技巧:]",
|
||||
"\\\\begin{sphinxadmonition}{attention}{注意:}":
|
||||
"\\\\begin{tcolorbox}[colframe={warningframecolor},colback={warningbackcolor},coltitle=white,fonttitle=\\\\bfseries,title=注意:]",
|
||||
"\\\\begin{sphinxadmonition}{hint}{提示:}":
|
||||
"\\\\begin{tcolorbox}[colframe={hintframecolor},colback={hintbackcolor},coltitle=white,fonttitle=\\\\bfseries,title=提示:]",
|
||||
"\\\\end{sphinxadmonition}": "\\\\end{tcolorbox}",
|
||||
"\\\\begin{sphinxadmonition}{note}{Note:}":
|
||||
"\\\\begin{tcolorbox}[colframe={noteframecolor},colback={notebackcolor},coltitle=white,fonttitle=\\\\bfseries,title=Note:]",
|
||||
"\\\\begin{sphinxadmonition}{warning}{Warning:}":
|
||||
"\\\\begin{tcolorbox}[colframe={warningframecolor},colback={warningbackcolor},coltitle=white,fonttitle=\\\\bfseries,title=Warning:]",
|
||||
"\\\\begin{sphinxadmonition}{tip}{Tip:}":
|
||||
"\\\\begin{tcolorbox}[colframe={noteframecolor},colback={notebackcolor},coltitle=white,fonttitle=\\\\bfseries,title=Tip:]",
|
||||
"\\\\begin{sphinxadmonition}{attention}{Attention:}":
|
||||
"\\\\begin{tcolorbox}[colframe={warningframecolor},colback={warningbackcolor},coltitle=white,fonttitle=\\\\bfseries,title=Attention:]",
|
||||
"\\\\begin{sphinxadmonition}{hint}{Hint:}":
|
||||
"\\\\begin{tcolorbox}[colframe={hintframecolor},colback={hintbackcolor},coltitle=white,fonttitle=\\\\bfseries,title=Hint:]"
|
||||
},
|
||||
"customoptions": [
|
||||
"% \\\\numberwithin{figure}{chapter}",
|
||||
"% \\\\numberwithin{table}{chapter}",
|
||||
"\\\\titleformat{\\\\chapter}{\\\\raggedleft\\\\huge\\\\bfseries\\\\color{white}}{\\\\thechapter}{0.5em}{}",
|
||||
"\\\\titlespacing{\\\\chapter}{10pt}{40pt}{25pt}",
|
||||
"\\\\definecolor{noteframecolor}{RGB}{91,163,235}",
|
||||
"\\\\definecolor{notebackcolor}{RGB}{222,237,251}",
|
||||
"\\\\definecolor{warningframecolor}{RGB}{235,162,28}",
|
||||
"\\\\definecolor{warningbackcolor}{RGB}{255,247,236}",
|
||||
"\\\\definecolor{hintframecolor}{RGB}{70,193,196}",
|
||||
"\\\\definecolor{hintbackcolor}{RGB}{226,254,249}",
|
||||
"\\\\definecolor{camblue}{RGB}{0,89,196}",
|
||||
"% \\\\SetWatermarkText{Cambricon}",
|
||||
"% \\\\SetWatermarkLightness{0.9}",
|
||||
"% \\\\SetWatermarkScale{1}",
|
||||
"\\\\renewcommand{\\\\labelitemi}{$\\\\vcenter{\\\\hbox{\\\\scriptsize$\\\\bullet$}}$}",
|
||||
"\\\\definecolor{shadecolor}{RGB}{220,220,220}"
|
||||
],
|
||||
"isfiguretabletoc": {
|
||||
"comment": "插图目录英文:List of Figures;表格目录英文:List of Tables.",
|
||||
"isfigurestoc": false,
|
||||
"istablestoc": true,
|
||||
"figurestoc": [
|
||||
"\\\\renewcommand\\\\listfigurename{插\\ 图\\ 目\\ 录}",
|
||||
"\\\\listoffigures"
|
||||
],
|
||||
"tablestoc": [
|
||||
"\\\\renewcommand\\\\listtablename{表\\ 格\\ 目\\ 录}",
|
||||
"\\\\listoftables"
|
||||
]
|
||||
},
|
||||
"tables": {
|
||||
"comment":
|
||||
"isname:true-根据表格的name属性查找表格,false-根据表格的标题查找表格。isLongTable:true-强制设置为长表格,false-不设置长表格。isVertical:true-对第一列进行渲染,false-不对第一列进行渲染。isCusHead:true-对第一行进行渲染,false-不对第一行进行渲染。",
|
||||
"isname": true,
|
||||
"rowtype": "",
|
||||
"headtype": "{camblue!100}",
|
||||
"headfontcolor": "\\textbf{\\textcolor{white}{}}",
|
||||
"styles": [
|
||||
{
|
||||
"align": "centering",
|
||||
"caption": "allfilestandard",
|
||||
"captionalign": "left",
|
||||
"isLongTable": false,
|
||||
"isVertical": false,
|
||||
"isCusHead": true,
|
||||
"fontsize": "footnotesize",
|
||||
"ispartial": true
|
||||
},
|
||||
{
|
||||
"align": "centering",
|
||||
"caption": "gptconfignumber",
|
||||
"captionalign": "left",
|
||||
"isLongTable": false,
|
||||
"isVertical": false,
|
||||
"isCusHead": true,
|
||||
"fontsize": "footnotesize",
|
||||
"ispartial": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"image": {
|
||||
"styles": [
|
||||
{
|
||||
"name": "",
|
||||
"align": "",
|
||||
"caption": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
"sensitivewords": [
|
||||
"安防",
|
||||
"监听",
|
||||
"stream",
|
||||
"hisi",
|
||||
"展讯",
|
||||
"英伟达",
|
||||
"nvidia",
|
||||
"讯飞",
|
||||
"展锐",
|
||||
"c10",
|
||||
"c20",
|
||||
"IK",
|
||||
"AH",
|
||||
"US",
|
||||
"MLU320"
|
||||
],
|
||||
"ignorewarndes": [
|
||||
"该字段已废弃不再使用,但不能删掉,否则会导致编译错误!"
|
||||
],
|
||||
"ignorewarnkey": [
|
||||
"sdk_memory.rst && 文档没有加入到任何目录树中",
|
||||
"sdk_memory.rst && document isn't included in any toctree",
|
||||
"Package hyperref Warning",
|
||||
"LaTeX Font Warning",
|
||||
"Package cmap Warning",
|
||||
"Package xeCJK Warning"
|
||||
]
|
||||
|
||||
}
|
||||
327
torch_mlu_ops-v1.3.2/docs/user_guide/source/conf.py
Executable file
327
torch_mlu_ops-v1.3.2/docs/user_guide/source/conf.py
Executable file
@@ -0,0 +1,327 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# pylint: disable=C0301, C0305
|
||||
#
|
||||
# Torch-MLU-Ops documentation build configuration file, created by
|
||||
# sphinx-quickstart on Tue Apr 23 18:33:05 2020.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its
|
||||
# containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#
|
||||
# import os
|
||||
# import sys
|
||||
# sys.path.insert(0, os.path.abspath('.'))
|
||||
from __future__ import print_function
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#
|
||||
# needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
#import sys
|
||||
#reload(sys)
|
||||
#sys.setdefaultencoding('utf-8')
|
||||
extensions = [
|
||||
'sphinx.ext.mathjax',
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix(es) of source filenames.
|
||||
# You can specify multiple suffix as a list of string:
|
||||
#
|
||||
# source_suffix = ['.rst', '.md']
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'寒武纪Torch-MLU-Ops用户手册'
|
||||
copyright = u'2024, Cambricon'
|
||||
author = u''
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = u'1.3.2'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = version
|
||||
curfnpre=u'Cambricon-Torch-MLU-Ops-User-Guide-CN-v'
|
||||
curfn=curfnpre + version + '.tex'
|
||||
today = ""
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#
|
||||
# This is also used if you do content translation via gettext catalogs.
|
||||
# Usually you set "language" from the command line for these cases.
|
||||
language = 'zh_CN'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This patterns also effect to html_static_path and html_extra_path
|
||||
exclude_patterns = ['_build','_venv','_templates']
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
||||
todo_include_todos = False
|
||||
|
||||
smartquotes = False
|
||||
numfig = True
|
||||
numfig_secnum_depth = 1
|
||||
# -- Options for HTML output ----------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
html_copy_source = False
|
||||
html_css_files = [
|
||||
'custom.css',
|
||||
]
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
#
|
||||
# html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['../_static']
|
||||
|
||||
# Custom sidebar templates, must be a dictionary that maps document names
|
||||
# to template names.
|
||||
#
|
||||
# This is required for the alabaster theme
|
||||
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
|
||||
html_sidebars = {
|
||||
'**': [
|
||||
'relations.html', # needs 'show_related': True theme option to display
|
||||
'searchbox.html',
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
# -- Options for HTMLHelp output ------------------------------------------
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'Torch-MLU-Opsdoc'
|
||||
|
||||
|
||||
# -- Options for LaTeX output ---------------------------------------------
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title,
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
(master_doc, curfn, u'寒武纪Torch-MLU-Ops用户手册',
|
||||
author, 'manual'),
|
||||
]
|
||||
|
||||
|
||||
# xelatex 作为 latex 渲染引擎,因为可能有中文渲染
|
||||
latex_engine = 'xelatex'
|
||||
|
||||
# 如果没有使用自定义封面,可以加上封面 logo。这里可以是 pdf 或者 png,jpeg 等
|
||||
latex_logo = "./logo.png"
|
||||
|
||||
latex_use_latex_multicolumn = True
|
||||
latex_show_urls = 'footnote'
|
||||
|
||||
latex_use_xindy = False
|
||||
# 主要的配置,用于控制格式等
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#
|
||||
'papersize': 'a4paper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#
|
||||
# 'pointsize': '8pt',
|
||||
|
||||
'inputenc': '',
|
||||
'utf8extra': '',
|
||||
'figure_align': 'H',
|
||||
'releasename':"版本",
|
||||
'sphinxsetup': '''
|
||||
verbatimwithframe=false,
|
||||
verbatimwrapslines=true,
|
||||
VerbatimColor={RGB}{220,220,220},
|
||||
verbatimhintsturnover=false,
|
||||
''',
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
'preamble': '''
|
||||
\\addto\\captionsenglish{\\renewcommand{\\chaptername}{}}
|
||||
|
||||
% 设置字体
|
||||
|
||||
\\usepackage{xeCJK}
|
||||
\\usepackage{fontspec}
|
||||
\\CJKsetecglue{\\hskip0.08em plus0.01em minus 0.01em}
|
||||
\\defaultfontfeatures[\\rmfamily,\\sffamily,\\ttfamily]{}
|
||||
\\setCJKmainfont{Noto Sans CJK SC}[AutoFakeSlant]
|
||||
\\setCJKsansfont{Noto Sans CJK SC}[AutoFakeSlant]
|
||||
\\setCJKmonofont{Noto Sans Mono CJK SC}[AutoFakeSlant]
|
||||
\\setmainfont{Noto Sans CJK SC}[AutoFakeSlant]
|
||||
|
||||
% 以下配置将页面的可显示范围调宽
|
||||
% 调宽后背景图一定要使用chapterbkpaper_width.pdf,否则一级标题的显示效果会很差
|
||||
\\geometry{
|
||||
top=26mm,
|
||||
bottom=22mm,
|
||||
left=10mm,
|
||||
right=10mm,
|
||||
}
|
||||
|
||||
%%清除 latex headheight small错误编译告警
|
||||
\\setlength{\\headheight}{14.0pt}
|
||||
|
||||
% 段首缩进 2 格
|
||||
|
||||
%\\usepackage{indentfirst}
|
||||
%\\setlength{\\parindent}{2em}
|
||||
|
||||
\\usepackage{setspace}
|
||||
|
||||
% 1.5 倍行间距
|
||||
\\renewcommand{\\baselinestretch}{1.5}
|
||||
% 表格里的行间距
|
||||
\\renewcommand{\\arraystretch}{1.5}
|
||||
|
||||
% list 列表的缩进对齐
|
||||
\\usepackage{enumitem}
|
||||
\\setlist{nosep}
|
||||
|
||||
% 表格类的宏包
|
||||
\\usepackage{threeparttable}
|
||||
\\usepackage{array}
|
||||
\\usepackage{booktabs}
|
||||
|
||||
% fancy 页眉页脚
|
||||
\\usepackage{fancyhdr}
|
||||
\\pagestyle{fancy}
|
||||
|
||||
% 在 sphinx 生成的 tex 文件里,normal 是指普通页面(每一个章节里,除了第一页外剩下的页面)
|
||||
% 页眉,L:left,R:right,E:even,O:odd
|
||||
% 奇数页面:左边是 leftmark,章号和章名称;右边是 rightmark,节号与节名称
|
||||
% 偶数页面:左边是 rightmark,节号与节名称;右边是 leftmark,章号和章名称
|
||||
% textsl 是字体,slanted shape,对于英语而言,某种斜体。但是不同于 textit 的 italic shape
|
||||
% 左页脚:版权信息
|
||||
% 右页脚:页码数
|
||||
% rulewidth:页眉和页脚附近的横线的粗细,当设置为 0pt 时,就没有该横线
|
||||
%
|
||||
\\fancypagestyle{normal} {
|
||||
\\fancyhf{}
|
||||
\\fancyhead{}
|
||||
\\fancyhead[LE,RO]{\\textsl{\\rightmark}}
|
||||
\\fancyhead[LO,RE]{\\textsl{\\leftmark}}
|
||||
\\lfoot{Copyright © 2024 Cambricon Corporation.}
|
||||
\\rfoot{\\thepage}
|
||||
\\renewcommand{\\headrulewidth}{0.4pt}
|
||||
\\renewcommand{\\footrulewidth}{0.4pt}
|
||||
}
|
||||
|
||||
% 在 sphinx 生成的 tex 文件里,plain 是指每个章节的第一页等
|
||||
\\fancypagestyle{plain} {
|
||||
\\fancyhf{}
|
||||
% left head 还可以内嵌图片,图片可以是 pdf,png,jpeg 等
|
||||
% \\lhead{\\includegraphics[height=40pt]{cn_tm.pdf}}
|
||||
\\lhead{\\large\\textcolor[rgb]{0.1804,0.4588,0.7137}{Cambricon®}}
|
||||
\\lfoot{Copyright © 2024 Cambricon Corporation.}
|
||||
\\rfoot{\\thepage}
|
||||
\\renewcommand{\\headrulewidth}{0.4pt}
|
||||
\\renewcommand{\\footrulewidth}{0.4pt}
|
||||
}
|
||||
''',
|
||||
|
||||
|
||||
#
|
||||
'printindex': r'\footnotesize\raggedright\printindex',
|
||||
|
||||
|
||||
# 移除空白页面
|
||||
'extraclassoptions': 'openany,oneside',
|
||||
|
||||
# 如果需要用 latex 自已做封面,可以使用 maketitle
|
||||
# 下面这个封面的例子来自于互联网
|
||||
|
||||
# 'maketitle': r'''
|
||||
# \pagenumbering{Roman} %%% to avoid page 1 conflict with actual page 1
|
||||
#
|
||||
# \begin{titlepage}
|
||||
# \centering
|
||||
#
|
||||
# \vspace*{40mm} %%% * is used to give space from top
|
||||
# \textbf{\Huge {Sphinx format for Latex and HTML}}
|
||||
#
|
||||
# \vspace{0mm}
|
||||
# \begin{figure}[!h]
|
||||
# \centering
|
||||
# \includegraphics[width=0.8\textwidth]{cn.png}
|
||||
# \end{figure}
|
||||
#
|
||||
# % \vspace{0mm}
|
||||
# % \Large \textbf{{Meher Krishna Patel}}
|
||||
#
|
||||
# % \small Created on : Octorber, 2017
|
||||
#
|
||||
# % \vspace*{0mm}
|
||||
# % \small Last updated : \MonthYearFormat\today
|
||||
#
|
||||
#
|
||||
# %% \vfill adds at the bottom
|
||||
# % \vfill
|
||||
# % \small \textit{More documents are freely available at }{\href{http://pythondsp.readthedocs.io/en/latest/pythondsp/toc.html}{PythonDSP}}
|
||||
# \end{titlepage}
|
||||
#
|
||||
# \clearpage
|
||||
# \pagenumbering{roman}
|
||||
# \tableofcontents
|
||||
# \listoffigures
|
||||
# \listoftables
|
||||
# \clearpage
|
||||
# \pagenumbering{arabic}
|
||||
#
|
||||
# ''',
|
||||
#
|
||||
} # latex_elements
|
||||
|
||||
import os.path as osp
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
try:
|
||||
# conf_callback.py一般和conf.py放在同一目录下即可,如果有特殊需求请根据conf_callback.py的实际路径进行修改。
|
||||
if osp.exists(osp.join(osp.dirname(__file__), r'./conf_callback.py')):
|
||||
sys.path.append(osp.join(osp.dirname(__file__), '.'))
|
||||
else:
|
||||
sys.path.append(osp.join(osp.dirname(__file__), '../'))
|
||||
|
||||
from conf_callback import *
|
||||
|
||||
except Exception as e:
|
||||
# 如果出现了异常,请检查上面默认配置的两个路径是否满足要求,如果不满足要求,请修改上面的路径直到没异常发生。
|
||||
print(e)
|
||||
traceback.print_exc()
|
||||
#app.setup_extension('custoctree')
|
||||
370
torch_mlu_ops-v1.3.2/docs/user_guide/source/conf_callback.py
Normal file
370
torch_mlu_ops-v1.3.2/docs/user_guide/source/conf_callback.py
Normal file
@@ -0,0 +1,370 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
# sphinx事件回调函数
|
||||
#如果copy到conf.py文件中,只copy下面的代码即可。
|
||||
|
||||
import os
|
||||
import os.path as osp
|
||||
import sys
|
||||
import importlib
|
||||
import traceback
|
||||
import datetime as dt
|
||||
import locale
|
||||
|
||||
#如果文档编译失败,请检查下面默认的路径是否正确,请根据实际路径进行修改
|
||||
|
||||
curpath = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
if osp.exists(osp.join(osp.dirname(__file__), './parsejson.py')):
|
||||
sys.path.append(osp.join(osp.dirname(__file__), '.'))
|
||||
else:
|
||||
sys.path.append(osp.join(osp.dirname(__file__), '../'))
|
||||
|
||||
cusdirect = None
|
||||
extpathisexist = False # ./_ext/customdirective.py是否存在的标志,用于设置指令扩展
|
||||
|
||||
extpath = osp.join(osp.dirname(__file__), './_ext')
|
||||
if osp.exists(extpath):
|
||||
# 自定义指令所在路径,加到搜索目录,否则无法使用自定义指令
|
||||
sys.path.append(extpath)
|
||||
if osp.exists(osp.join(osp.dirname(__file__),r'./_ext/customdirective.py')):
|
||||
extpathisexist = True
|
||||
cusdirect = importlib.import_module('customdirective')
|
||||
else:
|
||||
extpath = osp.join(osp.dirname(__file__), '../_ext')
|
||||
sys.path.append(extpath)
|
||||
if osp.exists(osp.join(osp.dirname(__file__),r'../_ext/customdirective.py')):
|
||||
extpathisexist = True
|
||||
cusdirect = importlib.import_module('customdirective')
|
||||
|
||||
import sphinx
|
||||
import sphinx.errors as sperror
|
||||
import parsejson
|
||||
|
||||
try:
|
||||
import breathe # 仅为了判断版本号,根据breathe版本号添加不同配置
|
||||
breathe_version = breathe.__version__[:3]
|
||||
except Exception as e:
|
||||
breathe_version = ""
|
||||
|
||||
warnfile = '' # 告警文件,不包含路径
|
||||
warnfilepath = '' # 保存告警日志文件,包含完整的路径名
|
||||
|
||||
months=['January','February','March','April','May','June','July',
|
||||
'August','September','October','Novmber','December']
|
||||
|
||||
gmaketitle = r'''
|
||||
\pagenumbering{Roman}
|
||||
\begin{titlepage}
|
||||
\centering
|
||||
\vspace*{40mm}
|
||||
\textbf{\Huge {%(titlename)s}}
|
||||
|
||||
\vspace{10mm}
|
||||
\textbf{\Large{%(release)s}}
|
||||
|
||||
\vfill
|
||||
\textbf{\large{%(today)s}}
|
||||
\end{titlepage}
|
||||
'''
|
||||
|
||||
def __ModifyMakeTitle(elementskeys,config):
|
||||
'''
|
||||
如果有maketitle变量则修改maketitle的内容
|
||||
:param config: 配置变量
|
||||
:return:
|
||||
'''
|
||||
#得到封面名称
|
||||
titlename = config.latex_documents[0][2]
|
||||
|
||||
if 'releasename' in elementskeys:
|
||||
releasename = config.latex_elements['releasename']
|
||||
else:
|
||||
releasename = ''
|
||||
|
||||
if hasattr(config,'version'):
|
||||
version = config.version
|
||||
else:
|
||||
version = ''
|
||||
release = releasename +' ' + version
|
||||
if hasattr(config,'today') and len(config.today) > 0:
|
||||
today = config.today
|
||||
else:
|
||||
todayft = dt.date.today()
|
||||
if hasattr(config,'language') and config.language=='zh_CN':
|
||||
today = todayft.strftime('%Y 年 %m 月 %d 日')
|
||||
else:
|
||||
#除中文外,一律用英文时间格式
|
||||
#得到英文月的全称。
|
||||
month = months[int(todayft.strftime('%m'))-1]
|
||||
today = month + todayft.strftime(" %d, %Y")
|
||||
|
||||
if len(config.latex_elements['maketitle'].strip())==0:
|
||||
maketitle = gmaketitle
|
||||
else:
|
||||
maketitle = config.latex_elements['maketitle']
|
||||
#必须转一下,否则赋值不成功
|
||||
config.latex_elements['maketitle'] = maketitle % {
|
||||
'titlename': titlename,
|
||||
'release': release,
|
||||
'today': today
|
||||
}
|
||||
def docview_modifyconfig(config):
|
||||
"""
|
||||
以下配置需要在config_init事件中配置,否则有些变量无法读取到,导致配置不生效
|
||||
:param config:
|
||||
:return:
|
||||
"""
|
||||
#配置静态路径
|
||||
if len(config.html_static_path)==0:
|
||||
#如果配置了,就以配置路径为准,否则默认提供两个可选路径
|
||||
if osp.exists(curpath + '/_static'):
|
||||
config.html_static_path = [curpath + '/_static']
|
||||
else:
|
||||
config.html_static_path = [curpath + '/../_static']
|
||||
|
||||
texfilename = config.latex_documents[0][1] #得到tex文件名,构建pdf文件名
|
||||
filename,fileext = os.path.splitext(texfilename)
|
||||
pdfname = filename+'.pdf'
|
||||
#设置js脚本
|
||||
config.html_js_files = [('custom.js', {'pdfname': pdfname}),'cndeveloper.js']
|
||||
config.html_css_files = ['custom.css']
|
||||
|
||||
def modifycommonconfig(config):
|
||||
"""
|
||||
以下配置为通用配置,为了配置生效,放在setup函数中调用。
|
||||
:param config:
|
||||
:return:
|
||||
"""
|
||||
#设置html通用配置
|
||||
#设置html最新更新时间
|
||||
config.html_last_updated_fmt = '%Y-%m-%d %H:%M:%S'
|
||||
config.html_theme = 'sphinx_rtd_theme'
|
||||
config.html_copy_source = False
|
||||
config.html_show_sphinx = False
|
||||
|
||||
#设置latex通用配置
|
||||
config.latex_use_latex_multicolumn = True
|
||||
config.latex_use_xindy = False
|
||||
config.latex_engine = 'xelatex'
|
||||
#修改通用配置
|
||||
config.smartquotes = False
|
||||
config.numfig = True
|
||||
config.numfig_secnum_depth = 1
|
||||
|
||||
|
||||
|
||||
def config_inited_handler(app, config):
|
||||
# 检查年份是否正确,并修改。需配合最新parsejson.py文件使用,否则不支持该接口。
|
||||
# 通用配置的修改放在该位置,否则对配置的修改不生效
|
||||
try:
|
||||
# 该函数的第二个参数可以传入版权声明文件相对于conf.py的相对路径,自动修改版权声明的年份
|
||||
# 比如:parsejson.CheckCurrentYearAndModify(app,'../source/copyright/cnperf_conpyright.rst')
|
||||
# 默认路径为“./copyright/copyright.rst”和“./copyright/copyright_zh.rst”或者“./copyright/copyright_en.rst”
|
||||
# 以上三个路径无需传入
|
||||
parsejson.CheckCurrentYearAndModify(app)
|
||||
except Exception as e:
|
||||
print('------------------')
|
||||
print(e)
|
||||
# traceback.print_stack()
|
||||
traceback.print_exc()
|
||||
print('------------------')
|
||||
|
||||
try:
|
||||
# print(sphinx.__version__)
|
||||
# app.require_sphinx('3.5')
|
||||
keys = config.latex_elements.keys()
|
||||
if 'sphinxsetup' not in keys:
|
||||
config.latex_elements['sphinxsetup'] = ''
|
||||
if "3.5" <= sphinx.__display_version__[:3]:
|
||||
config.latex_elements['sphinxsetup'] = 'verbatimforcewraps=true,verbatimmaxunderfull=2,' + \
|
||||
config.latex_elements['sphinxsetup']
|
||||
if "5.3" <= sphinx.__display_version__[:3]:
|
||||
config.latex_table_style = ['standard', 'nocolorrows']
|
||||
config.latex_elements['sphinxsetup'] += 'pre_border-radius=0pt,'
|
||||
if len(breathe_version) > 0 and "4.3" <= breathe_version:
|
||||
config.latex_elements['preamble'] += '''
|
||||
\\renewenvironment{description}
|
||||
{\\list{}{\\labelwidth=0pt
|
||||
\\let\\makelabel\\descriptionlabel}}
|
||||
{\\endlist}
|
||||
'''
|
||||
#如果有自定义maketitle,则修改maketitle的内容
|
||||
if 'maketitle' in keys:
|
||||
__ModifyMakeTitle(keys,config)
|
||||
|
||||
docview_modifyconfig(config)
|
||||
# sphinxsetup = config.latex_elements['sphinxsetup']
|
||||
# print('sphinxversion:%s;sphinxsetup:%s' % (sphinx.__version__,sphinxsetup))
|
||||
except Exception as e:
|
||||
# print('sphinxversion:%s %s' % (sphinx.__version__,sphinx.__display_version__[:3]))
|
||||
pass
|
||||
|
||||
|
||||
def build_finished_handler(app, exception):
|
||||
if exception != None:
|
||||
# print(exception)
|
||||
return
|
||||
|
||||
# 判断告警文件是否存在,只有无告警或者告警全是忽略告警才允许继续后续的编译
|
||||
if warnfilepath != '' and osp.exists(warnfilepath):
|
||||
# 判断告警文件中是否全是忽略告警
|
||||
iswarn = parsejson.warn_main(warnfilepath, app)
|
||||
if iswarn:
|
||||
# 如果为True则说明有不可忽略的告警,报sphinxerror异常,停止继续编译
|
||||
raise sperror.SphinxError('There are alarms, please check the file of %s for details' % warnfile)
|
||||
return
|
||||
|
||||
try:
|
||||
if app.builder.name == "latex":
|
||||
selffnlst = app.config.latex_documents
|
||||
parsejson.Modifylatex_main(app.outdir, selffnlst, app)
|
||||
except Exception as e:
|
||||
print('------------------')
|
||||
print(e)
|
||||
traceback.print_exc()
|
||||
|
||||
# 检查html标题一致性。该接口最好放在该位置,主索引文件的标题已经解析出来。
|
||||
# if app.builder.name == "html":
|
||||
# result = parsejson.CheckProjectNameIsConsistent(app)
|
||||
# if result != "":
|
||||
# raise sperror.SphinxError(result) #带raise的异常如果用except捕捉,则在终端打印告警将不能显示为红色字体。
|
||||
|
||||
|
||||
def build_inited_handler(app):
|
||||
global warnfile
|
||||
global warnfilepath
|
||||
|
||||
print(sys.argv)
|
||||
args = sys.argv[1:] # 0为sphinx-build,需忽略掉
|
||||
if '-w' in args:
|
||||
pos = args.index('-w') # 找到-w所在的索引位置
|
||||
warnfile = args[pos + 1] # 得到告警保存的文件名
|
||||
# print('warnfile=' + warnfile)
|
||||
|
||||
# 根据工作路径,得到文件名的绝对路径
|
||||
# 当前在build阶段,因此工作路径为Makefile所在的目录,-w后面的文件保存在基于Makefile的相对路径下
|
||||
filepath = osp.join(os.getcwd(), warnfile)
|
||||
warnfilepath = osp.abspath(filepath)
|
||||
# print('warnfilepath = ' + warnfilepath)
|
||||
|
||||
# try:
|
||||
# # 检查是否有rst_prolog或者rst_epilog替换内容,有的话去掉前后空格
|
||||
# # 仅适用于pdf文件和中文文档,英文文档和html不启作用
|
||||
# checkDocobj = parsejson.clsCheckDocCopyrightYear(app, "")
|
||||
# if app.builder.name == 'latex' or app.builder.name == 'latexpdf':
|
||||
# checkDocobj.CheckReplaceContent()
|
||||
# except Exception as e:
|
||||
# print('------------------')
|
||||
# print(e)
|
||||
# traceback.print_exc()
|
||||
# print('------------------')
|
||||
|
||||
# try:
|
||||
# # 检查html配置是否符合规范。必须放在这个位置,否则app没有builder对象。
|
||||
# if app.builder.name == "html":
|
||||
# error = parsejson.CheckHtmlConfigIsCorrect(app)
|
||||
# if error != "":
|
||||
# raise sperror.ConfigError(error)
|
||||
# except Exception as e:
|
||||
# print('------------------')
|
||||
# print(e)
|
||||
# traceback.print_stack()
|
||||
# traceback.print_exc()
|
||||
# print('------------------')
|
||||
|
||||
|
||||
def source_read_handler(app, docname, source):
|
||||
if cusdirect is not None:
|
||||
cnonlyobj = cusdirect.CNOnlyPro(app, docname, source[0])
|
||||
source[0] = cnonlyobj.parsecnonlycontent(source[0])
|
||||
|
||||
# try:
|
||||
# 自动添加更新历史代码,默认添加“无内容更新”
|
||||
# source[0] = parsejson.CheckUpdateHistory(app, docname, source[0])
|
||||
# except Exception as e:
|
||||
# print('------------------')
|
||||
# print(e)
|
||||
# traceback.print_exc()
|
||||
# print('------------------')
|
||||
|
||||
return source
|
||||
|
||||
|
||||
def doctree_resolved_handle(app, doctree, docname):
|
||||
"""
|
||||
删除不需要文件的内容,避免编译html的时候还进行编译,导致内容泄漏
|
||||
"""
|
||||
if not hasattr(app.config, 'enable_exclude_html') or not app.config.enable_exclude_html:
|
||||
# 默认按sphinx方式编译所有rst文件到html
|
||||
return
|
||||
|
||||
indexname = app.config.master_doc
|
||||
if docname == indexname:
|
||||
return
|
||||
indexdocnames = app.env.toctree_includes[indexname]
|
||||
isexist = False
|
||||
# 判断文档是否在索引文件里
|
||||
if docname not in indexdocnames:
|
||||
newtoctree = app.env.toctree_includes.copy()
|
||||
del newtoctree[indexname] # 删除主索引文件,因为无需比较
|
||||
for key in newtoctree.keys():
|
||||
values = newtoctree[key]
|
||||
if docname in values:
|
||||
isexist = True
|
||||
# 判断该key是否在主索引文件里面
|
||||
if key not in indexdocnames:
|
||||
# 如果不在整个的索引文件里面,删除该文件内容
|
||||
# doctree.attributes['source']=''
|
||||
while len(doctree.children) > 0:
|
||||
doctree.remove(doctree.children[0])
|
||||
# 删除标题,否则html页面还有标题,还需要维护标题
|
||||
for node in app.env.titles[docname].children:
|
||||
app.env.titles[docname].remove(node)
|
||||
if not isexist:
|
||||
# 文档不在toctree字典里,直接删除内容
|
||||
while len(doctree.children) > 0:
|
||||
doctree.remove(doctree.children[0])
|
||||
# 删除标题,否则html页面还有标题,还需要维护标题
|
||||
for node in app.env.titles[docname].children:
|
||||
app.env.titles[docname].remove(node)
|
||||
|
||||
|
||||
def setup(app):
|
||||
"""
|
||||
该函数中的路径都是相对于工程builder环境的路径而不是相对于conf.py所在的路径,
|
||||
该函数外面的相对路径是相对于conf.py的路径没有问题。
|
||||
比如./_ext相对路径是相对于工程的路径,因此如果使用abspath得到绝对路径会得到~/m0_docs/_ext/,
|
||||
而不是~ / mo_docs / source / _ext。
|
||||
因此该路径下对路径的判断最好转化为绝对路径判断,否则可能会判断失败。
|
||||
:param app:
|
||||
:return:
|
||||
"""
|
||||
#将通用配置放在这个位置,因为有些配置比如html_theme,在config_init事件前就已读取,不允许再修改
|
||||
#放在setup函数中,提前预配置项才能生效。
|
||||
modifycommonconfig(app.config)
|
||||
|
||||
app.connect('config-inited', config_inited_handler)
|
||||
app.connect('build-finished', build_finished_handler)
|
||||
app.connect('builder-inited', build_inited_handler)
|
||||
app.connect('source-read', source_read_handler)
|
||||
app.connect('doctree-resolved', doctree_resolved_handle)
|
||||
|
||||
app.add_config_value('chapterbkpaper_image', '', 'env', [str])
|
||||
# 是否排除未添加到index的html文件。在编译html时,sphinx默认会将所有rst文件都生成html,因此可能会造成部分内容的泄露。
|
||||
# 为了删除这部分内容,设置该变量。如果置为True的话,将删除不在index.rst里面的html的内容。
|
||||
# 默认为false,不做处理,以增加编译效率。
|
||||
# 建议还是将不参与编译的rst文件,放到exclude_patterns变量内,放到该变量后,rst不参与编译,能提高编译效率。
|
||||
app.add_config_value('enable_exclude_html', False, 'env', [bool])
|
||||
#配置版权声明文件完整路径,实现版权声明文件年份的自动修改。
|
||||
#parsejson.CheckCurrentYearAndModify如果该函数中传入了版权声明的全路径,则以该函数中传入的为准
|
||||
#在该处又增加了一个配置值,是为了配置和代码解偶,为了兼容性,保留了原来的配置方式
|
||||
app.add_config_value('copyfile_path', '', 'env', [str])
|
||||
#在conf.py中配置的conf.json路径,为了实现conf.json配置的灵活处理
|
||||
app.add_config_value('confjson_path', '', 'env', [str])
|
||||
|
||||
if extpathisexist:
|
||||
app.setup_extension('customdirective')
|
||||
20
torch_mlu_ops-v1.3.2/docs/user_guide/source/index.rst
Normal file
20
torch_mlu_ops-v1.3.2/docs/user_guide/source/index.rst
Normal file
@@ -0,0 +1,20 @@
|
||||
.. torch_mlu_ops_rst documentation master file, created by
|
||||
sphinx-quickstart on Mon Apr 22 19:17:54 2019.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
寒武纪Torch-MLU-Ops用户手册
|
||||
===========================================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 5
|
||||
:caption: 目录
|
||||
:numbered:
|
||||
|
||||
./tmo_1_copyright/index
|
||||
./tmo_2_preface/index
|
||||
./tmo_3_overview/index
|
||||
./tmo_4_installation/index
|
||||
./tmo_5_key_features/index
|
||||
./tmo_6_best_practice/index
|
||||
./tmo_7_FAQ/index
|
||||
BIN
torch_mlu_ops-v1.3.2/docs/user_guide/source/logo.png
Normal file
BIN
torch_mlu_ops-v1.3.2/docs/user_guide/source/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
30
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_1_copyright/index.rst
Executable file
30
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_1_copyright/index.rst
Executable file
@@ -0,0 +1,30 @@
|
||||
.. copyright
|
||||
|
||||
版权声明
|
||||
==========================================
|
||||
|
||||
**免责声明**
|
||||
|
||||
中科寒武纪科技股份有限公司(下称“寒武纪”)不代表、担保(明示、暗示或法定的)或保证本文件所含信息,并明示放弃对可销售性、所有权、不侵犯知识产权或特定目的适用性做出任何和所有暗示担保,且寒武纪不承担因应用或使用任何产品或服务而产生的任何责任。寒武纪不应对因下列原因产生的任何违约、损害赔偿、成本或问题承担任何责任:(1)使用寒武纪产品的任何方式违背本指南;或(2)客户产品设计。
|
||||
|
||||
**责任限制**
|
||||
|
||||
在任何情况下,寒武纪都不对因使用或无法使用本指南而导致的任何损害(包括但不限于利润损失、业务中断和信息损失等损害)承担责任,即便寒武纪已被告知可能遭受该等损害。尽管客户可能因任何理由遭受任何损害,根据寒武纪的产品销售条款与条件,寒武纪为本指南所述产品对客户承担的总共和累计责任应受到限制。
|
||||
|
||||
**信息准确性**
|
||||
|
||||
本文件提供的信息属于寒武纪所有,且寒武纪保留不经通知随时对本文件信息或对任何产品和服务做出任何更改的权利。本指南所含信息和本指南所引用寒武纪文档的所有其他信息均“按原样”提供。寒武纪不担保信息、文本、图案、链接或本指南内所含其他项目的准确性或完整性。寒武纪可不经通知随时对本指南或本指南所述产品做出更改,但不承诺更新本指南。
|
||||
|
||||
本指南列出的性能测试和等级要使用特定芯片或计算机系统或组件来测量。经该等测试,本指南所示结果反映了寒武纪产品的大概性能。系统硬件或软件设计或配置的任何不同会影响实际性能。如上所述,寒武纪不代表、担保或保证本指南所述产品将适用于任何特定用途。寒武纪不代表或担保测试每种产品的所有参数。客户全权承担确保产品适合并适用于客户计划的应用以及对应用程序进行必要测试的责任,以期避免应用程序或产品的默认情况。
|
||||
|
||||
客户产品设计的脆弱性会影响寒武纪产品的质量和可靠性并导致超出本指南范围的额外或不同的情况和/或要求。
|
||||
|
||||
**知识产权通知**
|
||||
|
||||
寒武纪和寒武纪的标志是中科寒武纪科技股份有限公司在中国和其他国家的商标和/或注册商标。其他公司和产品名称应为与其关联的各自公司的商标。
|
||||
|
||||
本指南为版权所有并受全世界版权法律和条约条款的保护。未经寒武纪的事先书面许可,不可以任何方式复制、重制、修改、出版、上传、发布、传输或分发本指南。除了客户使用本指南信息和产品的权利,根据本指南,寒武纪不授予其他任何明示或暗示的权利或许可。未免疑义,寒武纪不根据任何专利、版权、商标、商业秘密或任何其他寒武纪的知识产权或所有权对客户授予任何(明示或暗示的)权利或许可。
|
||||
|
||||
* 版权声明
|
||||
|
||||
* © 2024 中科寒武纪科技股份有限公司保留一切权利。
|
||||
112
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_2_preface/index.rst
Executable file
112
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_2_preface/index.rst
Executable file
@@ -0,0 +1,112 @@
|
||||
更新历史
|
||||
==========================================
|
||||
* **V1.3.2**
|
||||
|
||||
**更新时间**: 2025年01月09日
|
||||
|
||||
**更新内容**:
|
||||
|
||||
- ``fused_layer_norm`` 与 ``fused_rms_norm`` 的输入和输出支持更多的 ``stride`` 组合。请参考 :ref:`torch_mlu_ops.fused_rms_norm`、:ref:`torch_mlu_ops.fused_layer_norm` 章节。
|
||||
|
||||
* **V1.3.1**
|
||||
|
||||
**更新时间**: 2024年12月30日
|
||||
|
||||
**更新内容**:
|
||||
|
||||
- ``smooth_quant_group_gemm`` 与 ``fused_moe`` 算子支持w4w8混合量化。请参考 :ref:`torch_mlu_ops.smooth_quant_group_gemm` 和 :ref:`torch_mlu_ops.fused_moe` 章节。
|
||||
- 新增 ``dequant_from_paged_cache`` 算子,详细内容请参考 :ref:`torch_mlu_ops.dequant_from_paged_cache` 章节。
|
||||
- ``dequant_from_linear_cache`` 算子不再支持float32的 ``key`` 和 ``value``。
|
||||
- 新增 :ref:`gen_case` 功能。
|
||||
- 新增 :ref:`pt_example` 章节内容。
|
||||
|
||||
* **V1.3.0**
|
||||
|
||||
**更新时间**: 2024年12月17日
|
||||
|
||||
**更新内容**:
|
||||
|
||||
- ``group_gemm`` 与 ``smooth_quant_group_gemm`` 算子的 ``max_m`` 参数由可选修改为必选。请参考 :ref:`torch_mlu_ops.group_gemm` 和 :ref:`torch_mlu_ops.smooth_quant_group_gemm` 章节。
|
||||
- ``moe_softmax_topk`` 支持mask功能,请参考 :ref:`torch_mlu_ops.moe_softmax_topk` 章节。
|
||||
- 新增 ``dequant_from_linear_cache`` 算子,详细内容请参考 :ref:`torch_mlu_ops.dequant_from_linear_cache` 章节。
|
||||
|
||||
* **V1.2.3**
|
||||
|
||||
**更新时间**: 2024年12月09日
|
||||
|
||||
**更新内容**:
|
||||
|
||||
- ``single_query_cached_kv_attn`` 与 ``flash_attention`` 算子支持 ``head_size_qk != head_size_v``,请参考 :ref:`torch_mlu_ops.single_query_cached_kv_attn` 和 :ref:`torch_mlu_ops.flash_attention` 章节。
|
||||
- ``group_gemm`` 与 ``smooth_quant_group_gemm`` 算子支持bias,请参考 :ref:`torch_mlu_ops.group_gemm` 和 :ref:`torch_mlu_ops.smooth_quant_group_gemm` 章节。
|
||||
- ``matmul`` 删除原位输出参数,增加指定输出类型参数,请参考 :ref:`torch_mlu_ops.matmul` 章节。
|
||||
|
||||
* **V1.2.2**
|
||||
|
||||
**更新时间**: 2024年11月08日
|
||||
|
||||
**更新内容**:
|
||||
|
||||
- ``smooth_quant_group_gemm`` 算子新增int4 group量化功能,请参考 :ref:`torch_mlu_ops.smooth_quant_group_gemm` 章节。
|
||||
- allreduce类算子删除act_mode,请参考 :ref:`torch_mlu_ops.smooth_quant_matmul_allreduce` 和 :ref:`torch_mlu_ops.matmul_allreduce` 章节。
|
||||
- ``weight_only_quant_matmul`` 与 ``smooth_quant_matmul`` 添加use_hp_active参数,控制激活计算方式, 请参考 :ref:`torch_mlu_ops.weight_only_quant_matmul` 和 :ref:`torch_mlu_ops.smooth_quant_matmul` 章节。
|
||||
- ``active`` 算子新增quick_gelu和swish激活模式,请参考 :ref:`torch_mlu_ops.active` 章节。
|
||||
|
||||
* **V1.2.1**
|
||||
|
||||
**更新时间**: 2024年11月04日
|
||||
|
||||
**更新内容**:
|
||||
|
||||
- ``quant_to_linear_cache`` 算子新增group量化及int4量化功能,请参考 :ref:`torch_mlu_ops.quant_to_linear_cache` 章节。
|
||||
- 新增 ``moe_cast_gating`` 算子,请参考 :ref:`torch_mlu_ops.moe_cast_gating` 章节。
|
||||
- 新增 ``update_out_and_lse`` 算子,请参考 :ref:`torch_mlu_ops.update_out_and_lse` 章节。
|
||||
- ``fused_rope`` 算子支持int8/int4 kv cache。
|
||||
- ``matmul`` 与 ``batch_matmul`` 新增配置 ``trans_a``, ``trans_b`` 参数,请参考 :ref:`torch_mlu_ops.matmul` 和 :ref:`torch_mlu_ops.batch_matmul` 章节。
|
||||
- ``single_query_cached_kv_attn`` 支持int4 kv cache,支持返回lse。请参考 :ref:`torch_mlu_ops.single_query_cached_kv_attn` 章节。
|
||||
- 新增 ``single_query_mixed_cached_kv_attn`` 算子。
|
||||
- ``fused_layer_norm`` 与 ``fused_rms_norm`` 支持输出动态量化。请参考 :ref:`torch_mlu_ops.fused_rms_norm`、:ref:`torch_mlu_ops.fused_layer_norm` 章节。
|
||||
|
||||
* **V1.2.0**
|
||||
|
||||
**更新时间**: 2024年10月24日
|
||||
|
||||
**更新内容**:
|
||||
|
||||
- ``moe_softmax_topk`` 算子新增grouped_topk功能,请参考 :ref:`torch_mlu_ops.moe_softmax_topk` 章节。
|
||||
- ``moe_softmax_topk`` 算子不再支持原位功能,请参考 :ref:`torch_mlu_ops.moe_softmax_topk` 章节。
|
||||
- ``moe_gen_idx`` 算子不再支持原位功能,请参考 :ref:`torch_mlu_ops.moe_gen_idx` 章节。
|
||||
- 新增 ``fused rope`` 算子,请参考 :ref:`torch_mlu_ops.fused_rope` 章节。
|
||||
- ``matmul`` 算子支持INT8输入,请参考 :ref:`torch_mlu_ops.matmul` 章节。
|
||||
- 新增 ``batch_matmul`` 算子,请参考 :ref:`torch_mlu_ops.batch_matmul` 章节。
|
||||
|
||||
* **V1.1.4**
|
||||
|
||||
**更新时间**: 2024年09月30日
|
||||
|
||||
**更新内容**:
|
||||
|
||||
- 新增 ``offline_quant_to_paged_cache`` 算子,详见 :ref:`torch_mlu_ops.offline_quant_to_paged_cache` 章节。
|
||||
- 新增 ``moe_gen_idx`` 和 ``moe_expand_input`` 算子,详见 :ref:`torch_mlu_ops.moe_gen_idx` 和 `torch_mlu_ops.expand_input` 章节。
|
||||
- 新增 ``moe_combine_result`` 算子,详见 :ref:`torch_mlu_ops.moe_combine_result` 章节。
|
||||
- 新增 ``moe_gen_idx`` 算子,详见 :ref:`torch_mlu_ops.moe_gen_idx` 章节。
|
||||
- 删除 ``quant_matmul`` 算子,由 ``smooth_quant_matmul`` 和 ``weight_only_quant_matmul`` 实现其功能, 详见 :ref:`torch_mlu_ops.smooth_quant_matmul` 和 :ref:`torch_mlu_ops.weight_only_quant_matmul` 章节。
|
||||
- ``flash_attention`` 算子新增 ``block_tables`` 、 ``k/v_cache_quant_scale`` 参数。请参考 :ref:`torch_mlu_ops.flash_attention` 章节。
|
||||
- ``matmul`` 算子支持激活计算方式配置,请参考 :ref:`torch_mlu_ops.matmul` 章节。
|
||||
- FAQ章节新增对 ``flash_attention`` 算子的说明,请参考 :ref:`FAQ` 章节。
|
||||
- 新增 ``moe_active`` 算子,详见 :ref:`torch_mlu_ops.moe_active` 章节。
|
||||
|
||||
* **V1.1.3**
|
||||
|
||||
**更新时间**: 2024年09月06日
|
||||
|
||||
**更新内容**:
|
||||
|
||||
- BangTransformer更名为Torch-MLU-Ops, 定位PyTorch第三方算子库。
|
||||
- 原BangTransformer网络评测相关文档请参考《寒武纪BangTransformer用户手册》v1.1.2版本。
|
||||
- bt_ops的命名空间变化为torch_mlu_ops, 请参考 :ref:`torch_mlu_ops`。
|
||||
- torch_mlu_ops.single_query_cached_kv_attn算子支持per_token量化和per_channel量化。
|
||||
- torch_mlu_ops.fused_moe算子在非量化情况下支持EP模式,内部支持group gemm和allreduce并行。
|
||||
- 提供flash_attn_sq_mm_allreduce、matmul_allreduce、smooth_quant_matmul_allreduce通算融合算子,fused_moe支持通算融合。请参考 :ref:`torch_mlu_ops.flash_attn_sq_mm_allreduce`、
|
||||
:ref:`torch_mlu_ops.matmul_allreduce`、:ref:`torch_mlu_ops.smooth_quant_matmul_allreduce`、:ref:`torch_mlu_ops.fused_moe`。
|
||||
- torch_mlu_ops.flash_attention、torch_mlu_ops.single_query_cached_kv_attn、torch_mlu_ops.fused_rms_norm、torch_mlu_ops.fused_layer_norm支持原位输出。请参考 :ref:`torch_mlu_ops.flash_attention`、
|
||||
:ref:`torch_mlu_ops.single_query_cached_kv_attn`、:ref:`torch_mlu_ops.fused_rms_norm`、:ref:`torch_mlu_ops.fused_layer_norm`。
|
||||
7
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_3_overview/index.rst
Executable file
7
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_3_overview/index.rst
Executable file
@@ -0,0 +1,7 @@
|
||||
.. _简介:
|
||||
|
||||
简介
|
||||
==========================
|
||||
|
||||
.. toctree::
|
||||
tmo_overview
|
||||
27
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_3_overview/tmo_overview.rst
Executable file
27
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_3_overview/tmo_overview.rst
Executable file
@@ -0,0 +1,27 @@
|
||||
应用场景
|
||||
===============================
|
||||
|
||||
Torch-MLU-Ops是寒武纪设计和开发的PyTorch第三方算子库。对于使用PyTorch框架的开发者,通过Torch-MLU-Ops,能够便捷地使用这些自定义算子,进行算子的集成、评测和业务部署。
|
||||
|
||||
Torch-MLU-Ops已全量覆盖LLM(Large Language Model)推理场景下的常见算子。作为后端,已支持Cambricon vLLM、Cambricon TGI、Cambricon Stable Diffusion web UI、Cambricon ComfyUI以及Cambricon Diffusers。
|
||||
|
||||
.. _关键特性:
|
||||
|
||||
关键特性
|
||||
===============================
|
||||
Torch-MLU-Ops在支持LLM模型部署时提供的关键特性如下所示:
|
||||
|
||||
- PyTorch风格的算子API
|
||||
- 支持LLM推理场景下的常见算子
|
||||
- Flash Attention支持Multi-head Attention、Multi-query Attention、Group-query Attention特性
|
||||
- 支持KV Cache INT8特性
|
||||
- Single Query Cached Attention算子支持Paged特性
|
||||
- 矩阵乘类算子支持Weight-only、AWQ、GPTQ、Smoothquant量化特性
|
||||
- 支持MOE场景下常见算子
|
||||
- 提供不同融合力度的融合算子
|
||||
- 提供通信——计算融合算子MC2
|
||||
- 支持Cambricon TGI调用
|
||||
- 支持Cambricon vLLM调用
|
||||
- 支持Cambricon Stable Diffusion web UI调用
|
||||
- 支持Cambricon ComfyUI调用
|
||||
- 支持Cambricon Diffusers调用
|
||||
7
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_4_installation/index.rst
Executable file
7
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_4_installation/index.rst
Executable file
@@ -0,0 +1,7 @@
|
||||
.. _编译安装:
|
||||
|
||||
安装和部署
|
||||
============================
|
||||
|
||||
.. toctree::
|
||||
tmo_installation
|
||||
@@ -0,0 +1,165 @@
|
||||
.. _hostinstall:
|
||||
|
||||
在主机上安装和部署
|
||||
==========================================
|
||||
|
||||
环境要求
|
||||
--------------
|
||||
|
||||
- Torch-MLU-Ops在不同的操作系统上有不同的软件版本依赖。
|
||||
|
||||
不同平台支持的软件版本如下:
|
||||
|
||||
.. table:: Torch-MLU-Ops不同平台支持软件版本
|
||||
:widths: 20 20 20
|
||||
|
||||
+--------------------+----------------------+--------------------+
|
||||
| 平台 | 编译器版本 | CMake版本 |
|
||||
+====================+======================+====================+
|
||||
| Ubuntu22.04 x86-64 | gcc 9.4.0或更高版本 | 3.10或更高版本 |
|
||||
+--------------------+----------------------+--------------------+
|
||||
| Debian10.11 x86.64 | gcc 9.4.0或更高版本 | 3.10或更高版本 |
|
||||
+--------------------+----------------------+--------------------+
|
||||
|
||||
- 编译、运行Torch-MLU-Ops同时还需要配置以下依赖。
|
||||
|
||||
.. table:: Torch-MLU-Ops配置依赖
|
||||
:name: cppdemorely
|
||||
|
||||
+------------------+-------------------+---------+-------------+---------+-------------+
|
||||
| Torch-MLU-Ops | Torch-MLU | CNNL | CNNL_Extra | CNCL | CNToolkit |
|
||||
+==================+===================+=========+=============+=========+=============+
|
||||
| v1.3.2 | v1.24.1 | v1.28.3 | v1.12.3 | v1.24.1 | v3.15.6 |
|
||||
+------------------+-------------------+---------+-------------+---------+-------------+
|
||||
| v1.3.1 | v1.24.1 | v1.28.3 | v1.12.2 | v1.24.1 | v3.15.5 |
|
||||
+------------------+-------------------+---------+-------------+---------+-------------+
|
||||
| v1.3.0 | v1.24.0 | v1.28.2 | v1.12.1 | v1.24.0 | v3.15.4 |
|
||||
+------------------+-------------------+---------+-------------+---------+-------------+
|
||||
| v1.2.3 | v1.24.0 | v1.28.1 | v1.12.1 | v1.24.0 | v3.15.3 |
|
||||
+------------------+-------------------+---------+-------------+---------+-------------+
|
||||
| v1.2.2 | v1.23.1 | v1.27.4 | v1.11.3 | v1.23.0 | v3.14.3 |
|
||||
+------------------+-------------------+---------+-------------+---------+-------------+
|
||||
| v1.2.1 | v1.23.1 | v1.27.3 | v1.11.3 | v1.22.3 | v3.14.2 |
|
||||
+------------------+-------------------+---------+-------------+---------+-------------+
|
||||
| v1.2.0 | v1.23.0 | v1.27.1 | v1.11.1 | v1.22.1 | v3.14.1 |
|
||||
+------------------+-------------------+---------+-------------+---------+-------------+
|
||||
| v1.1.4 | v1.22.2 | v1.26.7 | v1.10.4 | v1.21.1 | v3.13.7 |
|
||||
+------------------+-------------------+---------+-------------+---------+-------------+
|
||||
| v1.1.3 | v1.22.2 | v1.26.6 | v1.10.3 | v1.21.1 | v3.13.5 |
|
||||
+------------------+-------------------+---------+-------------+---------+-------------+
|
||||
|
||||
- 此外运行Torch-MLU-Ops还依赖PyTorch环境。Torch-MLU-Ops已支持的PyTorch版本请参考。
|
||||
|
||||
.. table:: Torch-MLU-Ops支持的PyTorch版本
|
||||
:name: pytorchdepends
|
||||
|
||||
+------------------+-------------------+
|
||||
| Torch-MLU-Ops | PyTorch |
|
||||
+==================+===================+
|
||||
| v1.3.2 | v2.1, v2.4, v2.5 |
|
||||
+------------------+-------------------+
|
||||
| v1.3.1 | v2.1, v2.4, v2.5 |
|
||||
+------------------+-------------------+
|
||||
| v1.3.0 | v2.1, v2.4, v2.5 |
|
||||
+------------------+-------------------+
|
||||
| v1.2.3 | v2.1, v2.4, v2.5 |
|
||||
+------------------+-------------------+
|
||||
| v1.2.2 | v2.1, v2.4, v2.5 |
|
||||
+------------------+-------------------+
|
||||
| v1.2.1 | v2.1, v2.4, v2.5 |
|
||||
+------------------+-------------------+
|
||||
| v1.2.0 | v2.1, v2.4, v2.5 |
|
||||
+------------------+-------------------+
|
||||
| v1.1.4 | v2.1, v2.3, v2.4 |
|
||||
+------------------+-------------------+
|
||||
| v1.1.3 | v2.1, v2.3 |
|
||||
+------------------+-------------------+
|
||||
|
||||
|
||||
通过docker镜像启动
|
||||
--------------------
|
||||
|
||||
寒武纪提供的PyTorch解决方案镜像已提供了Torch-MLU-Ops所需要的依赖,请参考PyTorch解决方案镜像的使用手册启动镜像。
|
||||
|
||||
|
||||
编译安装
|
||||
--------------------
|
||||
|
||||
Torch-MLU-Ops编译脚本依赖于NEUWARE_HOME环境变量,该环境变量指向寒武纪CNToolkit的安装路径,通常为 ``/usr/local/neuware`` 。
|
||||
|
||||
在运行示例程序前,您需要将 ``NEUWARE_HOME`` 中的 ``lib64`` 目录添加到 ``LD_LIBRARY_PATH`` 环境变量中,例如:
|
||||
|
||||
::
|
||||
|
||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$NEUWARE_HOME/lib64
|
||||
|
||||
如果您使用寒武纪提供的docker镜像,以上环境变量均已经被设置好了。
|
||||
|
||||
设置好 ``NEUWARE_HOME`` 环境变量后,您可以使用以下命令编译Torch-MLU-Ops。
|
||||
|
||||
从远端clone仓库,进入项目的主目录:
|
||||
|
||||
::
|
||||
|
||||
cd torch_mlu_ops
|
||||
|
||||
源码安装:
|
||||
|
||||
::
|
||||
|
||||
pip install -e .
|
||||
|
||||
wheel包安装:
|
||||
|
||||
::
|
||||
|
||||
python setup.py bdist_wheel
|
||||
pip install dist/torch_mlu_ops*.whl
|
||||
|
||||
.. attention::
|
||||
|
||||
如果安装过程中遇到权限问题,请获取相关权限或切换到拥有权限的user执行pip install 这步操作。
|
||||
|
||||
移除Torch-MLU-Ops(Optional):
|
||||
|
||||
::
|
||||
|
||||
pip uninstall torch_mlu_ops
|
||||
|
||||
|
||||
测试
|
||||
---------------------------------------
|
||||
|
||||
在测试前,请确保Torch-MLU-Ops已安装。可以通过 ``pip list`` 命令查询Torch-MLU-Ops的安装情况。若有如下类似打印,则表明安装成功。
|
||||
|
||||
::
|
||||
|
||||
torch-mlu-ops 1.1.0+pt21
|
||||
|
||||
Torch-MLU-Ops模块的导入方法请参考。
|
||||
|
||||
::
|
||||
|
||||
import torch_mlu_ops as tmo
|
||||
|
||||
在 ``./tests/ops_pytest`` 目录下,提供了 ``ops`` 级别的测试示例程序,您可以参考如下命令进行测试。
|
||||
|
||||
::
|
||||
|
||||
cd tests/ops_pytest/
|
||||
./run_test.sh
|
||||
|
||||
或者单独测试某个测例,例如:
|
||||
|
||||
::
|
||||
|
||||
python test_flash_attention.py
|
||||
|
||||
|
||||
在 ``./tests/kernels_pytest`` 目录下,提供了 ``kernels`` 级别的测试示例程序,您可以参考如下命令进行测试。
|
||||
|
||||
::
|
||||
|
||||
cd tests/kernels_pytest
|
||||
./build.sh # 需要先编译
|
||||
./run_test.sh
|
||||
7
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_5_key_features/index.rst
Executable file
7
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_5_key_features/index.rst
Executable file
@@ -0,0 +1,7 @@
|
||||
.. _重点特性:
|
||||
|
||||
重点特性
|
||||
==========================
|
||||
|
||||
.. toctree::
|
||||
tmo_key_features
|
||||
2743
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_5_key_features/tmo_key_features.rst
Executable file
2743
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_5_key_features/tmo_key_features.rst
Executable file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
.. _最佳实践:
|
||||
|
||||
最佳实践
|
||||
==========================
|
||||
|
||||
.. toctree::
|
||||
|
||||
tmo_best_practice
|
||||
@@ -0,0 +1,200 @@
|
||||
.. _tmo_benchmark:
|
||||
|
||||
Torch-MLU-Ops性能benchmark测试
|
||||
==========================================
|
||||
|
||||
Torch-MLU-Ops benchmark测试脚本为用户提供了进行算子性能测试的便捷入口。
|
||||
|
||||
用户可通过以下命令获取各个参数的含义。
|
||||
|
||||
::
|
||||
|
||||
python3 benchmark_xxx.py --help
|
||||
|
||||
|
||||
各个参数含义如下:
|
||||
|
||||
- ``-h, --help``:显示帮助信息。
|
||||
- ``--repeat_times, REPEAT_TIMES``:配置测试重复次数。
|
||||
- ``--csv``:将报告数据输出到csv文件。
|
||||
- ``-o O``:当配置了 ``--csv`` 参数后,指定csv文件的输出目录。
|
||||
|
||||
测试命令示例如下:
|
||||
|
||||
::
|
||||
|
||||
python3 benchmark_active.py --repeat_times 10 --csv -o './active/'
|
||||
|
||||
支持如下算子:
|
||||
|
||||
|
||||
.. table:: Torch-MLU-Ops benchmark测试支持算子
|
||||
:name: spporttedops
|
||||
:class: longtable
|
||||
:widths: 10
|
||||
|
||||
+------------------------------------+
|
||||
| op_name |
|
||||
+====================================+
|
||||
| active |
|
||||
+------------------------------------+
|
||||
| apply_rotary |
|
||||
+------------------------------------+
|
||||
| attention_project |
|
||||
+------------------------------------+
|
||||
| combine_result |
|
||||
+------------------------------------+
|
||||
| ffn |
|
||||
+------------------------------------+
|
||||
| flash_attn |
|
||||
+------------------------------------+
|
||||
| fused_moe |
|
||||
+------------------------------------+
|
||||
| fused_norm_attention_project |
|
||||
+------------------------------------+
|
||||
| fused_norm_residual_ffn |
|
||||
+------------------------------------+
|
||||
| fused_rms_norm |
|
||||
+------------------------------------+
|
||||
| group_gemm |
|
||||
+------------------------------------+
|
||||
| matmul |
|
||||
+------------------------------------+
|
||||
| offline_quant_to_linear_cache |
|
||||
+------------------------------------+
|
||||
| per_token_smooth_quantize |
|
||||
+------------------------------------+
|
||||
| preload |
|
||||
+------------------------------------+
|
||||
| quantize |
|
||||
+------------------------------------+
|
||||
| quant_to_linear_cache |
|
||||
+------------------------------------+
|
||||
| reshape_linear_cache |
|
||||
+------------------------------------+
|
||||
| reshape_paged_cache |
|
||||
+------------------------------------+
|
||||
| single_query_cached_kv_attn |
|
||||
+------------------------------------+
|
||||
| smooth_quant_matmul |
|
||||
+------------------------------------+
|
||||
| weight_only_quant_matmul |
|
||||
+------------------------------------+
|
||||
|
||||
|
||||
|
||||
.. _gen_case:
|
||||
|
||||
Torch-MLU-Ops gen case
|
||||
==========================================
|
||||
|
||||
Torch-MLU-Ops 通过把算子参数信息保存成pt文件实现gen case功能。
|
||||
|
||||
gen case功能提供4个环境变量,如下所示:
|
||||
|
||||
- ``TMO_GEN_CASE``:值为1时开启dump case功能。
|
||||
- ``TMO_GEN_CASE_DUMP_DATA``:值为1时,所有参数均保存真值;``TMO_GEN_CASE_DUMP_DATA`` 不存在或为0时,则基础类型:int16、int32、int64类型的tensor,以及元素为整型的list保存真值。
|
||||
- ``TMO_GEN_CASE_OP_NAME``:指定需要dump case的算子名称,``torch_mlu_ops/_ops.py`` 文件的 ``__all__`` 列表记录的算子大部分已支持;如果不存在,则dump 程序运行过程中遇到的所有的TMO算子信息。
|
||||
- ``TMO_GEN_CASE_PATH``:指定case文件的输出目录,默认保存在当前目录下。
|
||||
|
||||
|
||||
使用示例:
|
||||
|
||||
::
|
||||
|
||||
export TMO_GEN_CASE=1
|
||||
python test_group_gemm.py
|
||||
bs: 1, seq_len: 5, k: 512, n: 512, experts_num: 8, topk: 2, dtype: torch.float16, idx_mode: False, has_bias: False testing...
|
||||
[torch_mlu_ops] dump case ====> tmo_gen_case/group_gemm/group_gemm_1734940034732854.pt
|
||||
bs: 1, seq_len: 5, k: 512, n: 512, experts_num: 8, topk: 2, dtype: torch.float16, idx_mode: True, has_bias: True testing...
|
||||
[torch_mlu_ops] dump case ====> tmo_gen_case/group_gemm/group_gemm_1734940034736277.pt
|
||||
|
||||
::
|
||||
|
||||
export TMO_GEN_CASE=1
|
||||
export TMO_GEN_CASE_DUMP_DATA=1
|
||||
export TMO_GEN_CASE_OP_NAME="group_gemm"
|
||||
python test_moe.py
|
||||
bs: 3, seq_len: 5, hidden_size: 512, inner_size: 768, experts_num: 8, start_expert_id: 4, expert_size: 2, topk: 2, gated: True, renormalize: True, data_type: torch.float16, act_mode: sil
|
||||
u testing...
|
||||
[torch_mlu_ops] dump case ====> tmo_gen_case/group_gemm/group_gemm_1735008239641861.pt
|
||||
[torch_mlu_ops] dump case ====> tmo_gen_case/group_gemm/group_gemm_1735008239672238.pt
|
||||
|
||||
.. _pt_example:
|
||||
|
||||
Torch-MLU-Ops 运行pt格式测例
|
||||
==========================================
|
||||
|
||||
使用 ``tests/ops_pytest/run_gen_case.py`` 文件运行pt格式的case。
|
||||
|
||||
::
|
||||
|
||||
python3 run_gen_case.py --help
|
||||
|
||||
|
||||
各个参数含义如下:
|
||||
|
||||
- ``-h, --help``:显示帮助信息。
|
||||
- ``--case_path CASE_PATH``:指定pt文件的路径。
|
||||
- ``--detail``:不运行case,只打印case信息。
|
||||
|
||||
测试命令示例如下:
|
||||
|
||||
::
|
||||
|
||||
python run_gen_case.py --case_path tmo_gen_case/group_gemm/group_gemm_1735008239672238.pt
|
||||
[torch_mlu_ops] run tmo_gen_case/group_gemm/group_gemm_1735008239672238.pt ...
|
||||
[torch_mlu_ops] run tmo_gen_case/group_gemm/group_gemm_1735008239672238.pt successfully
|
||||
|
||||
::
|
||||
|
||||
python run_gen_case.py --detail --case_path tmo_gen_case/group_gemm/group_gemm_1735008239672238.pt
|
||||
op: group_gemm
|
||||
dump_data: True
|
||||
a: tensor([[-7.5928e-02, 0.0000e+00, -2.9156e+01, ..., -0.0000e+00,
|
||||
1.3725e+02, -3.6625e+02],
|
||||
[-8.6609e-02, 4.9902e-01, 0.0000e+00, ..., -1.4185e-01,
|
||||
-2.5859e+01, -5.4844e+01],
|
||||
[ 4.5031e+01, 0.0000e+00, 8.7500e-01, ..., -9.3359e-01,
|
||||
1.3960e+03, -0.0000e+00],
|
||||
...,
|
||||
[ 0.0000e+00, 0.0000e+00, 0.0000e+00, ..., 0.0000e+00,
|
||||
0.0000e+00, 0.0000e+00],
|
||||
[ 2.0000e+00, -6.6250e+00, 5.1200e+02, ..., -6.5664e+00,
|
||||
5.1200e+02, 5.8984e+00],
|
||||
[-5.1200e+02, -5.5352e+00, 2.0000e+00, ..., 0.0000e+00,
|
||||
0.0000e+00, 0.0000e+00]], device='mlu:0', dtype=torch.float16)
|
||||
b: tensor([[[ 8.9502e-01, 2.5488e-01, -9.5947e-01, ..., 1.0635e+00,
|
||||
2.3848e+00, -1.8872e-01],
|
||||
[-1.4636e-01, -1.2900e+00, -3.3154e-01, ..., 1.3516e+00,
|
||||
5.0244e-01, 6.2012e-01],
|
||||
[ 1.3877e+00, 1.3916e-01, -6.0303e-01, ..., -1.6094e+00,
|
||||
-5.7861e-01, 1.3838e+00],
|
||||
...,
|
||||
[ 1.2350e-04, 4.5502e-02, 6.7041e-01, ..., 9.9316e-01,
|
||||
-4.0845e-01, -7.1777e-01],
|
||||
[-8.8818e-01, -1.3330e-01, -2.3779e-01, ..., -2.8662e-01,
|
||||
1.5908e+00, -7.5098e-01],
|
||||
[-1.0459e+00, -1.2305e+00, 8.1934e-01, ..., -1.6914e+00,
|
||||
-1.5176e+00, -1.4102e+00]],
|
||||
|
||||
[[-1.8301e+00, 7.3975e-01, -6.4575e-02, ..., 4.7534e-01,
|
||||
-2.6953e-01, -1.2490e+00],
|
||||
[-1.9775e-01, -1.9775e+00, -1.2598e+00, ..., -1.8860e-01,
|
||||
1.3220e-01, 9.9219e-01],
|
||||
[-8.6768e-01, -9.7949e-01, 2.9712e-01, ..., 1.0332e+00,
|
||||
7.2266e-02, -9.5068e-01],
|
||||
...,
|
||||
[ 3.0615e-01, 2.4023e+00, 1.1484e+00, ..., 1.0166e+00,
|
||||
4.0161e-01, -1.0527e+00],
|
||||
[ 3.8965e-01, -3.8867e-01, -1.0420e+00, ..., -1.3867e+00,
|
||||
1.1553e+00, -8.5938e-01],
|
||||
[-8.1152e-01, 2.6904e-01, -1.5840e+00, ..., 1.0518e+00,
|
||||
2.1855e+00, -1.6035e+00]]], device='mlu:0', dtype=torch.float16)
|
||||
m_list: tensor([6, 4], device='mlu:0', dtype=torch.int32)
|
||||
expand_idx: None
|
||||
c: None
|
||||
alpha: None
|
||||
beta: None
|
||||
max_m: 15
|
||||
bias: None
|
||||
32
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_7_FAQ/index.rst
Executable file
32
torch_mlu_ops-v1.3.2/docs/user_guide/source/tmo_7_FAQ/index.rst
Executable file
@@ -0,0 +1,32 @@
|
||||
.. _FAQ:
|
||||
|
||||
FAQ
|
||||
==========================================
|
||||
|
||||
|
||||
Cambricon Torch-MLU-Ops和BangTransformer的关系
|
||||
------------------------------------------------------------------------
|
||||
|
||||
Torch-MLU-Ops从BangTransformer演化而来,保留了BangTransformer提供的PyTorch第三方算子API能力,重新命名为Torch-MLU-Ops。原先BangTransformer的网络评测功能由Cambricon vLLM继承。
|
||||
|
||||
|
||||
Cambricon Torch-MLU-Ops和Cambricon PyTorch的关系
|
||||
------------------------------------------------------------------------
|
||||
|
||||
Cambricon PyTorch为能够运行在寒武纪设备上的PyTorch框架组件。Cambricon Torch-MLU-Ops为寒武纪PyTorch第三方算子库。在运行时,Torch-MLU-Ops需要依赖Cambricon PyTorch环境。
|
||||
|
||||
|
||||
Cambricon Torch-MLU-Ops和Cambricon MLU-Ops的关系
|
||||
------------------------------------------------------------------------
|
||||
|
||||
Cambricon Torch-MLU-Ops为寒武纪PyTorch第三方算子库,Cambricon MLU-Ops为寒武纪C++算子库,两者无直接关系。
|
||||
|
||||
|
||||
Cambricon Torch-MLU-Ops中 flash_attention 算子和Cambricon FlashAttention以及Cambricon PyTorch源生SDPA算子的关系
|
||||
--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Cambricon Torch-MLU-Ops中提供的 flash_attention 算子为专门为推理场景下定制优化的算子,后端调用的是CNNL_Extra组件中的 ``cnnlScaledDotProductAttn_v3`` 算子。
|
||||
|
||||
Cambricon FlashAttention和Cambricon PyTorch源生SDPA算子均针对训练场景,后端调用的是CNNL_Extra组件中的 ``cnnlFlashAttnFwd`` 和 ``cnnlFlashAttnBwd`` 算子。
|
||||
|
||||
针对推理场景下的flash attention算子测试,应当使用Cambricon Torch-MLU-Ops中的 flash_attention 算子,以获得MLU计算卡上更好的性能表现。
|
||||
Reference in New Issue
Block a user