Skip to content

Commit 66de4e0

Browse files
authored
DOC: update gen_docs (#4302)
1 parent c7d6617 commit 66de4e0

File tree

2 files changed

+57
-11
lines changed

2 files changed

+57
-11
lines changed

.github/workflows/pr_auto_run_gen_docs.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,21 @@ jobs:
8383
echo "[Debug] List ../main/doc/source:"
8484
ls -la ../main/doc/source || true
8585
86-
if [ -f "../main/doc/source/gen_docs.py" ]; then
86+
# Use PR branch's gen_docs.py if it exists, otherwise use main branch's
87+
if [ -f "doc/source/gen_docs.py" ]; then
88+
echo "Using PR branch's doc/source/gen_docs.py"
89+
echo "Running pr/doc/source/gen_docs.py from its directory"
90+
(cd doc/source && python -u gen_docs.py)
91+
elif [ -f "../main/doc/source/gen_docs.py" ]; then
8792
echo "Copying main/doc/source/gen_docs.py into PR workspace"
8893
mkdir -p doc/source
8994
cp -f ../main/doc/source/gen_docs.py doc/source/gen_docs.py
9095
echo "Running pr/doc/source/gen_docs.py from its directory"
9196
(cd doc/source && python -u gen_docs.py)
97+
elif [ -f "gen_docs.py" ]; then
98+
echo "Using PR branch's gen_docs.py"
99+
echo "Running pr/gen_docs.py"
100+
python -u gen_docs.py
92101
elif [ -f "../main/gen_docs.py" ]; then
93102
echo "Copying main/gen_docs.py into PR workspace"
94103
cp -f ../main/gen_docs.py gen_docs.py

doc/source/gen_docs.py

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def mock_engine_libraries():
3232
vllm_mock.__file__ = "mock_vllm.py"
3333

3434
# Create mock mlx module with core submodule
35-
35+
3636
mlx_mock = ModuleType('mlx')
37-
mlx_mock.__version__ = "0.1.0"
37+
mlx_mock.__version__ = "1.0.0"
3838
mlx_mock.__spec__ = ModuleSpec('mlx', None)
3939
mlx_mock.__file__ = "mock_mlx.py"
4040

@@ -56,25 +56,57 @@ def mock_engine_libraries():
5656
sglang_mock.__version__ = "0.3.0"
5757
sglang_mock.__spec__ = ModuleSpec('sglang', None)
5858
sglang_mock.__file__ = "mock_sglang.py"
59-
59+
60+
# Create mock xllamacpp module with proper module spec for importlib.util.find_spec
61+
import importlib.util
62+
import importlib.machinery
63+
64+
xllamacpp_mock = ModuleType('xllamacpp')
65+
xllamacpp_mock.__version__ = "1.0.0"
66+
67+
# Create a proper ModuleSpec that importlib.util.find_spec can find
68+
xllamacpp_spec = importlib.machinery.ModuleSpec('xllamacpp', None)
69+
xllamacpp_spec.origin = "mock_xllamacpp.py"
70+
xllamacpp_mock.__spec__ = xllamacpp_spec
71+
xllamacpp_mock.__file__ = "mock_xllamacpp.py"
72+
73+
# Create mock mlx_lm module
74+
mlx_lm_mock = ModuleType('mlx_lm')
75+
mlx_lm_mock.__version__ = "1.0.0"
76+
mlx_lm_mock.__spec__ = ModuleSpec('mlx_lm', None)
77+
mlx_lm_mock.__file__ = "mock_mlx_lm.py"
78+
79+
# Create mock mlx_vlm module
80+
mlx_vlm_mock = ModuleType('mlx_vlm')
81+
mlx_vlm_mock.__version__ = "1.0.0"
82+
mlx_vlm_mock.__spec__ = ModuleSpec('mlx_vlm', None)
83+
mlx_vlm_mock.__file__ = "mock_mlx_vlm.py"
84+
6085
# Mock these modules in sys.modules
6186
sys.modules['vllm'] = vllm_mock
6287
sys.modules['mlx'] = mlx_mock
6388
sys.modules['mlx.core'] = mlx_core_mock
6489
sys.modules['lmdeploy'] = lmdeploy_mock
6590
sys.modules['sglang'] = sglang_mock
91+
sys.modules['xllamacpp'] = xllamacpp_mock
92+
sys.modules['mlx_lm'] = mlx_lm_mock
93+
sys.modules['mlx_vlm'] = mlx_vlm_mock
6694

6795
# Apply mocking before importing xinference modules
6896
mock_engine_libraries()
6997

70-
from xinference.model.llm.llm_family import SUPPORTED_ENGINES, check_engine_by_spec_parameters
71-
from xinference.model.llm.vllm.core import VLLM_INSTALLED, VLLM_SUPPORTED_MODELS, VLLM_SUPPORTED_CHAT_MODELS
72-
73-
# Additional mocking for platform/hardware checks in documentation generation
98+
# Mock platform checks BEFORE importing xinference modules
7499
def mock_platform_checks():
75100
"""Mock platform and hardware checks for documentation generation"""
76101
from unittest.mock import patch
77-
102+
import sys
103+
import platform
104+
105+
# Mock platform system for MLX (make it appear as Apple Silicon)
106+
sys.platform = "darwin"
107+
platform.system = lambda: "Darwin"
108+
platform.processor = lambda: "arm"
109+
78110
# Mock vLLM platform checks
79111
import xinference.model.llm.vllm.core as vllm_core
80112
vllm_core.VLLMModel._is_linux = lambda: True
@@ -83,7 +115,7 @@ def mock_platform_checks():
83115
vllm_core.VLLMChatModel._has_cuda_device = lambda: True
84116
vllm_core.VLLMMultiModel._is_linux = lambda: True
85117
vllm_core.VLLMMultiModel._has_cuda_device = lambda: True
86-
118+
87119
# Mock SGLang platform checks if available
88120
try:
89121
import xinference.model.llm.sglang.core as sglang_core
@@ -95,7 +127,7 @@ def mock_platform_checks():
95127
sglang_core.SGLANGVisionModel._has_cuda_device = lambda: True
96128
except ImportError:
97129
pass
98-
130+
99131
# Mock LMDEPLOY platform checks if available
100132
try:
101133
import xinference.model.llm.lmdeploy.core as lmdeploy_core
@@ -108,6 +140,11 @@ def mock_platform_checks():
108140

109141
mock_platform_checks()
110142

143+
from xinference.model.llm.llm_family import SUPPORTED_ENGINES, check_engine_by_spec_parameters
144+
from xinference.model.llm.vllm.core import VLLM_INSTALLED, VLLM_SUPPORTED_MODELS, VLLM_SUPPORTED_CHAT_MODELS
145+
146+
# Mock platform checks again after imports to ensure they stick
147+
111148
# Re-register engines with mocked platform checks
112149
from xinference.model.llm import generate_engine_config_by_model_family
113150
from xinference.model.llm.llm_family import BUILTIN_LLM_FAMILIES, LLM_ENGINES

0 commit comments

Comments
 (0)