diff --git a/docs/vllm_mindspore/docs/source_en/conf.py b/docs/vllm_mindspore/docs/source_en/conf.py index f6864f092fea0e8274bc20873bb76de694da5908..ad0e9acc1b6d3165b944b9a2a648e2e2f9799656 100644 --- a/docs/vllm_mindspore/docs/source_en/conf.py +++ b/docs/vllm_mindspore/docs/source_en/conf.py @@ -10,16 +10,25 @@ # 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 glob import os +import re import shutil import sys -import IPython -import re import sphinx -sys.path.append(os.path.abspath('../_ext')) -import sphinx.ext.autosummary.generate as g from sphinx.ext import autodoc as sphinx_autodoc +import sphinx.ext.autosummary.generate as g + +# Fix some dl-label lack class='simple' +from docutils.writers import _html_base + +with open(_html_base.__file__, "r", encoding="utf-8") as f: + code_str = f.read() + old_str = ''' if self.is_compactable(node): + classes.append('simple')''' + new_str = ''' if classes == []: + classes.append('simple')''' + code_str = code_str.replace(old_str, new_str) + exec(code_str, _html_base.__dict__) # -- Project information ----------------------------------------------------- @@ -71,6 +80,13 @@ mathjax_options = { 'async':'async' } +nbsphinx_requirejs_path = 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js' + +nbsphinx_requirejs_options = { + "crossorigin": "anonymous", + "integrity": "sha256-1fEPhSsRKlFKGfK3eO710tEweHh1fwokU5wFGDHO+vg=" +} + smartquotes_action = 'De' exclude_patterns = [] @@ -85,23 +101,17 @@ autosummary_generate_overwrite = False # -- Options for HTML output ------------------------------------------------- -# Reconstruction of sphinx auto generated document translation. -language = 'zh_CN' -locale_dirs = ['../../../../resource/locale/'] -gettext_compact = False - # 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_search_language = 'zh' - -html_search_options = {'dict': '../../../resource/jieba.txt'} - -sys.path.append(os.path.abspath('../../../../resource/sphinx_ext')) -# import anchor_mod -import nbsphinx_mod +import sphinx_rtd_theme +layout_target = os.path.join(os.path.dirname(sphinx_rtd_theme.__file__), 'layout.html') +layout_src = '../../../../resource/_static/layout.html' +if os.path.exists(layout_target): + os.remove(layout_target) +shutil.copy(layout_src, layout_target) # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { @@ -109,25 +119,9 @@ intersphinx_mapping = { 'numpy': ('https://docs.scipy.org/doc/numpy/', '../../../../resource/numpy_objects.inv'), } -from sphinx import directives -with open('../_ext/overwriteobjectiondirective.txt', 'r', encoding="utf8") as f: - exec(f.read(), directives.__dict__) - -from sphinx.ext import viewcode -with open('../_ext/overwriteviewcode.txt', 'r', encoding="utf8") as f: - exec(f.read(), viewcode.__dict__) - -with open('../_ext/customdocumenter.txt', 'r', encoding="utf8") as f: - exec(f.read(), sphinx_autodoc.__dict__) - -# Modify regex for sphinx.ext.autosummary.generate.find_autosummary_in_lines. -gfile_abs_path = os.path.abspath(g.__file__) -autosummary_re_line_old = r"autosummary_re = re.compile(r'^(\s*)\.\.\s+autosummary::\s*')" -autosummary_re_line_new = r"autosummary_re = re.compile(r'^(\s*)\.\.\s+(ms[a-z]*)?autosummary::\s*')" -with open(gfile_abs_path, "r+", encoding="utf8") as f: - data = f.read() - data = data.replace(autosummary_re_line_old, autosummary_re_line_new) - exec(data, g.__dict__) +# # overwriteautosummary_generate add view source for api. +# with open('../_ext/overwriteautosummary_generate.txt', 'r', encoding="utf8") as f: +# exec(f.read(), g.__dict__) # Modify default signatures for autodoc. autodoc_source_path = os.path.abspath(sphinx_autodoc.__file__) @@ -139,16 +133,45 @@ import inspect as inspect_ def get_param_func(func): try: source_code = inspect_.getsource(func) - if func.__doc__: - source_code = source_code.replace(func.__doc__, '') - all_params_str = re.findall(r"def [\w_\d\-]+\(([\S\s]*?)(\):|\) ->.*?:)", source_code) - all_params = re.sub("(self|cls)(,|, )?", '', all_params_str[0][0].replace("\n", "").replace("'", "\"")) + all_params = '' + if hasattr(func, '__dataclass_fields__'): + for k, v in getattr(func, '__dataclass_fields__').items(): + if hasattr(v, 'default'): + if isinstance(v.default, str): + all_params += f"{k} = '{v.default}', " + else: + all_params += f"{k} = {v.default}, " + else: + all_params += f"{k}, " + all_params = all_params.strip(', ') + else: + if func.__doc__: + source_code = source_code.replace(func.__doc__, '') + all_params_str = re.findall(r"def [\w_\d\-]+\(([\S\s]*?)(\):|\) ->.*?:)", source_code) + if "@classmethod" in source_code or "def __new__" in source_code: + all_params = re.sub("(self|cls)(,|, )?", '', all_params_str[0][0].replace("\n", "")) + if ',' in all_params_str[0][0]: + all_params = re.sub("(self|cls)(, |,)", '', all_params_str[0][0].replace("\n", "")) + else: + all_params = re.sub("(self)(,|, )?", '', all_params_str[0][0].replace("\n", "")) + if ',' in all_params_str[0][0]: + all_params = re.sub("(self)(, |,)", '', all_params_str[0][0].replace("\n", "")) return all_params except: return '' def get_obj(obj): + if getattr(obj, '__dataclass_fields__', None): + return obj + if isinstance(obj, type): + try: + test_source = inspect_.getsource(obj.__init__) + except: + return obj.__new__ + obj_init = getattr(obj, '__init__', None) + if obj.__name__ not in str(obj_init) and hasattr(obj, '__new__'): + return obj.__new__ return obj.__init__ return obj @@ -160,7 +183,7 @@ with open(autodoc_source_path, "r+", encoding="utf8") as f: exec(get_param_func_str, sphinx_autodoc.__dict__) exec(code_str, sphinx_autodoc.__dict__) -# Copy source files of chinese python api from mindscience repository. +# Copy source files of chinese python api from vLLM MindSpore repository. from sphinx.util import logging logger = logging.getLogger(__name__) @@ -183,72 +206,45 @@ present_path = os.path.dirname(__file__) # shutil.copytree(os.path.join(src_dir,i),'./'+i) # copy_list.append(os.path.join(present_path,i)) -# add view +# get params for add view source import json -with open('../../../../tools/generate_html/daily.json', 'r+', encoding='utf-8') as f: - version_inf = json.load(f) +# if os.path.exists('../../../../tools/generate_html/version.json'): +# with open('../../../../tools/generate_html/version.json', 'r+', encoding='utf-8') as f: +# version_inf = json.load(f) +# elif os.path.exists('../../../../tools/generate_html/daily_dev.json'): +# with open('../../../../tools/generate_html/daily_dev.json', 'r+', encoding='utf-8') as f: +# version_inf = json.load(f) +# elif os.path.exists('../../../../tools/generate_html/daily.json'): +# with open('../../../../tools/generate_html/daily.json', 'r+', encoding='utf-8') as f: +# version_inf = json.load(f) # if os.getenv("VLLM_PATH").split('/')[-1]: # copy_repo = os.getenv("VLLM_PATH").split('/')[-1] # else: # copy_repo = os.getenv("VLLM_PATH").split('/')[-2] -# import pdb -# pdb.set_trace() - -# branch = [version_inf[i]['branch'] for i in range(len(version_inf)) if version_inf[i]['name'] == copy_repo][0] +# branch = [version_inf[i]['branch'] for i in range(len(version_inf)) if version_inf[i]['name'] == copy_repo.replace('-','_')][0] # docs_branch = [version_inf[i]['branch'] for i in range(len(version_inf)) if version_inf[i]['name'] == 'tutorials'][0] +# cst_module_name = 'mindformers' +# repo_whl = 'mindformers' +# giturl = 'https://gitee.com/mindspore/' + +# def setup(app): +# app.add_config_value('docs_branch', '', True) +# app.add_config_value('branch', '', True) +# app.add_config_value('cst_module_name', '', True) +# app.add_config_value('copy_repo', '', True) +# app.add_config_value('giturl', '', True) +# app.add_config_value('repo_whl', '', True) -# re_view = f"\n.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/{docs_branch}/" + \ -# f"resource/_static/logo_source_en.svg\n :target: https://gitee.com/mindspore/{copy_repo}/blob/{branch}/" - -# for cur, _, files in os.walk(present_path): -# for i in files: -# flag_copy = 0 -# if i.endswith('.rst'): -# for j in copy_list: -# if j in cur: -# flag_copy = 1 -# break -# if os.path.join(cur, i) in copy_list or flag_copy: -# try: -# with open(os.path.join(cur, i), 'r+', encoding='utf-8') as f: -# content = f.read() -# new_content = content -# if '.. include::' in content and '.. automodule::' in content: -# continue -# if 'autosummary::' not in content and "\n=====" in content: -# re_view_ = re_view + copy_path + cur.split(present_path)[-1] + '/' + i + \ -# '\n :alt: 查看源文件\n\n' -# new_content = re.sub('([=]{5,})\n', r'\1\n' + re_view_, content, 1) -# print("re_view_") -# print(re_view_) -# if new_content != content: -# f.seek(0) -# f.truncate() -# f.write(new_content) -# except Exception: -# print(f'打开{i}文件失败') - - -# import vllm_mindspore +sys.path.append(os.path.abspath('../../../../resource/sphinx_ext')) +# import anchor_mod +import nbsphinx_mod sys.path.append(os.path.abspath('../../../../resource/search')) import search_code -sys.path.append(os.path.abspath('../../../../resource/custom_directives')) -from custom_directives import IncludeCodeDirective -from myautosummary import MsPlatformAutoSummary, MsCnPlatformAutoSummary - -rst_files = set([i.replace('.rst', '') for i in glob.glob('./**/*.rst', recursive=True)]) - -def setup(app): - app.add_directive('msplatformautosummary', MsPlatformAutoSummary) - app.add_directive('mscnplatformautosummary', MsCnPlatformAutoSummary) - app.add_directive('includecode', IncludeCodeDirective) - app.add_config_value('rst_files', set(), False) - src_release = "./release_notes/release_notes.md" des_release = "./RELEASE.md" with open(src_release, "r", encoding="utf-8") as f: diff --git a/docs/vllm_mindspore/docs/source_en/getting_started/tutorials/qwen2.5_7b_singleNPU/qwen2.5_7b_singleNPU.md b/docs/vllm_mindspore/docs/source_en/getting_started/tutorials/qwen2.5_7b_singleNPU/qwen2.5_7b_singleNPU.md index 47ca1d4997b0b007261c65973c382345cd05b557..eb227e4ff9632e8dc0cba350e96f31e8187f680e 100644 --- a/docs/vllm_mindspore/docs/source_en/getting_started/tutorials/qwen2.5_7b_singleNPU/qwen2.5_7b_singleNPU.md +++ b/docs/vllm_mindspore/docs/source_en/getting_started/tutorials/qwen2.5_7b_singleNPU/qwen2.5_7b_singleNPU.md @@ -2,7 +2,7 @@ [![View Source](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/vllm_mindspore/docs/source_en/getting_started/tutorials/qwen2.5_7b_singleNPU/qwen2.5_7b_singleNPU.md) -This document introduces single NPU inference process by vLLM MindSpore. Taking the [Qwen2.5-7B](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) model as an example, user can configure the environment through the [Docker Installation](#docker-installation) or the [Installation Guide](../../installation/installation.md#installation-guide), and [download model weights](#download-model-weights). After [setting environment variables](#setting-environment-variables), user can perform [offline inference](#offline-inference) and [online inference](#online-inference) to experience single NPU inference abilities. +This document introduces single NPU inference process by vLLM MindSpore. Taking the [Qwen2.5-7B](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) model as an example, user can configure the environment through the [Docker Installation](#docker-installation) or the [Installation Guide](../../installation/installation.md#installation-guide), and [downloading model weights](#downloading-model-weights). After [setting environment variables](#setting-environment-variables), user can perform [offline inference](#offline-inference) and [online inference](#online-inference) to experience single NPU inference abilities. ## Docker Installation diff --git a/docs/vllm_mindspore/docs/source_en/user_guide/supported_features/benchmark/benchmark.md b/docs/vllm_mindspore/docs/source_en/user_guide/supported_features/benchmark/benchmark.md index d7eff67b57d152816b0215ad6f5dcd2194f11cb6..f6e66b1194b7bdc6e920f72a8c9df657b0fc04b2 100644 --- a/docs/vllm_mindspore/docs/source_en/user_guide/supported_features/benchmark/benchmark.md +++ b/docs/vllm_mindspore/docs/source_en/user_guide/supported_features/benchmark/benchmark.md @@ -2,7 +2,7 @@ [![View Source](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/vllm_mindspore/docs/source_en/user_guide/supported_features/benchmark/benchmark.md) -The benchmark tool of vLLM MindSpore is inherited from vLLM. You can refer to the [vLLM BenchMark](https://github.com/vllm-project/vllm/blob/main/benchmarks/README.md) documentation for more details. This document introduces [Online Benchmark](#online-performance-testing) and [Offline Benchmark](#offline-performance-testing). Users can follow the steps to conduct performance tests. +The benchmark tool of vLLM MindSpore is inherited from vLLM. You can refer to the [vLLM BenchMark](https://github.com/vllm-project/vllm/blob/main/benchmarks/README.md) documentation for more details. This document introduces [Online Benchmark](#online-benchmark) and [Offline Benchmark](#offline-benchmark). Users can follow the steps to conduct performance tests. ## Online Benchmark