Skip to content

Commit d81edc2

Browse files
q10facebook-github-bot
authored andcommitted
Fix python docs not being visible (pytorch#799)
Summary: Pull Request resolved: facebookresearch/FBGEMM#799 - Fix python docs not being visible. Bisection reveals that this bug first appeared in 887e5bf (pytorch#3477) X-link: pytorch#3717 Reviewed By: sryap Differential Revision: D69897513 Pulled By: q10 fbshipit-source-id: f04c1bb1986003161a2c81186b2981e39f95a4b7
1 parent 043fd18 commit d81edc2

File tree

6 files changed

+52
-11
lines changed

6 files changed

+52
-11
lines changed

.github/scripts/fbgemm_gpu_build.bash

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ __configure_fbgemm_gpu_build_cpu () {
145145
)
146146
}
147147

148+
__configure_fbgemm_gpu_build_docs () {
149+
# Update the package name and build args depending on if CUDA is specified
150+
echo "[BUILD] Setting CPU-only (docs) build args ..."
151+
build_args=(
152+
--package_variant=docs
153+
)
154+
}
155+
148156
__configure_fbgemm_gpu_build_rocm () {
149157
local fbgemm_variant_targets="$1"
150158

@@ -299,6 +307,10 @@ __configure_fbgemm_gpu_build () {
299307
echo "[BUILD] Configuring build as CPU variant ..."
300308
__configure_fbgemm_gpu_build_cpu
301309

310+
elif [ "$fbgemm_variant" == "docs" ]; then
311+
echo "[BUILD] Configuring build as CPU (docs) variant ..."
312+
__configure_fbgemm_gpu_build_docs
313+
302314
elif [ "$fbgemm_variant" == "rocm" ]; then
303315
echo "[BUILD] Configuring build as ROCm variant ..."
304316
__configure_fbgemm_gpu_build_rocm "${fbgemm_variant_targets}"
@@ -401,9 +413,10 @@ __build_fbgemm_gpu_common_pre_steps () {
401413
(test_binpath "${env_name}" g++) || return 1
402414

403415
# Set the default the FBGEMM_GPU variant to be CUDA
404-
if [ "$fbgemm_variant" != "cpu" ] &&
405-
[ "$fbgemm_variant" != "rocm" ] &&
406-
[ "$fbgemm_variant" != "genai" ]; then
416+
if [ "$fbgemm_variant" != "cpu" ] &&
417+
[ "$fbgemm_variant" != "docs" ] &&
418+
[ "$fbgemm_variant" != "rocm" ] &&
419+
[ "$fbgemm_variant" != "genai" ]; then
407420
echo "################################################################################"
408421
echo "[BUILD] Unknown FBGEMM_GPU variant: $fbgemm_variant"
409422
echo "[BUILD] Defaulting to CUDA"
@@ -501,7 +514,8 @@ __verify_library_symbols () {
501514

502515
# Prepare a sample set of symbols whose existence in the built library should be checked
503516
# This is by no means an exhaustive set, and should be updated accordingly
504-
if [ "${fbgemm_variant}" == "cpu" ]; then
517+
if [ "${fbgemm_variant}" == "cpu" ] ||
518+
[ "${fbgemm_variant}" == "docs" ]; then
505519
local lib_symbols_to_check=(
506520
fbgemm_gpu::asynchronous_inclusive_cumsum_cpu
507521
fbgemm_gpu::jagged_2d_to_dense
@@ -539,6 +553,7 @@ run_fbgemm_gpu_postbuild_checks () {
539553
echo "Usage: ${FUNCNAME[0]} FBGEMM_VARIANT"
540554
echo "Example(s):"
541555
echo " ${FUNCNAME[0]} cpu"
556+
echo " ${FUNCNAME[0]} docs"
542557
echo " ${FUNCNAME[0]} cuda"
543558
echo " ${FUNCNAME[0]} rocm"
544559
echo " ${FUNCNAME[0]} genai"
@@ -590,6 +605,7 @@ build_fbgemm_gpu_package () {
590605
echo "Usage: ${FUNCNAME[0]} ENV_NAME RELEASE_CHANNEL VARIANT [VARIANT_TARGETS]"
591606
echo "Example(s):"
592607
echo " ${FUNCNAME[0]} build_env release cpu # CPU-only variant"
608+
echo " ${FUNCNAME[0]} build_env release docs # CPU-only (docs) variant"
593609
echo " ${FUNCNAME[0]} build_env nightly cuda # CUDA variant for default target(s)"
594610
echo " ${FUNCNAME[0]} build_env test cuda '7.0;8.0' # CUDA variant for custom target(s)"
595611
echo " ${FUNCNAME[0]} build_env test rocm # ROCm variant for default target(s)"
@@ -659,6 +675,7 @@ build_fbgemm_gpu_install () {
659675
echo "Usage: ${FUNCNAME[0]} ENV_NAME VARIANT [TARGETS]"
660676
echo "Example(s):"
661677
echo " ${FUNCNAME[0]} build_env cpu # CPU-only variant"
678+
echo " ${FUNCNAME[0]} build_env docs # CPU-only (docs) variant"
662679
echo " ${FUNCNAME[0]} build_env cuda # CUDA variant for default target(s)"
663680
echo " ${FUNCNAME[0]} build_env cuda '7.0;8.0' # CUDA variant for custom target(s)"
664681
echo " ${FUNCNAME[0]} build_env rocm # ROCm variant for default target(s)"

.github/workflows/fbgemm_gpu_docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
run: . $PRELUDE; cd fbgemm_gpu; prepare_fbgemm_gpu_build $BUILD_ENV
8484

8585
- name: Build + Install FBGEMM_GPU (CPU version)
86-
run: . $PRELUDE; cd fbgemm_gpu; build_fbgemm_gpu_install $BUILD_ENV $BUILD_VARIANT
86+
run: . $PRELUDE; cd fbgemm_gpu; build_fbgemm_gpu_install $BUILD_ENV docs
8787

8888
- name: Build FBGEMM_GPU Documentation
8989
run: . $PRELUDE; cd fbgemm_gpu/docs; build_fbgemm_gpu_docs $BUILD_ENV

fbgemm_gpu/docs/src/fbgemm_gpu-development/BuildInstructions.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,9 @@ For CPU-only builds, the ``--cpu_only`` flag needs to be specified.
543543
python setup.py install \
544544
--package_variant=cpu
545545
546+
# NOTE: To build the package as part of generating the documentation, use
547+
# `--package_variant=docs` flag instead!
548+
546549
To build using Clang + ``libstdc++`` instead of GCC, simply append the
547550
``--cxxprefix`` flag:
548551

fbgemm_gpu/fbgemm_gpu/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
import torch
1212

1313

14-
def _load_library(filename: str) -> None:
14+
def _load_library(filename: str, no_throw: bool = False) -> None:
1515
"""Load a shared library from the given filename."""
1616
try:
1717
torch.ops.load_library(os.path.join(os.path.dirname(__file__), filename))
1818
logging.info(f"Successfully loaded: '{filename}'")
1919
except Exception as error:
2020
logging.error(f"Could not load the library '{filename}': {error}")
21-
raise error
21+
if not no_throw:
22+
raise error
2223

2324

2425
# Since __init__.py is only used in OSS context, we define `open_source` here
@@ -67,13 +68,24 @@ def _load_library(filename: str) -> None:
6768

6869
libraries_to_load = {
6970
"cpu": fbgemm_gpu_libraries,
71+
"docs": fbgemm_gpu_libraries,
7072
"cuda": fbgemm_gpu_libraries + fbgemm_gpu_genai_libraries,
7173
"genai": fbgemm_gpu_genai_libraries,
7274
"rocm": fbgemm_gpu_libraries,
7375
}
7476

7577
for library in libraries_to_load.get(__variant__, []):
76-
_load_library(f"{library}.so")
78+
# NOTE: In all cases, we want to throw an error if we cannot load the
79+
# library. However, this appears to break the OSS documentation build,
80+
# where the Python documentation doesn't show up in the generated docs.
81+
#
82+
# To work around this problem, we introduce a fake build variant called
83+
# `docs` and we only throw a library load error when the variant is not
84+
# `docs`. For more information, see:
85+
#
86+
# https://github.com/pytorch/FBGEMM/pull/3477
87+
# https://github.com/pytorch/FBGEMM/pull/3717
88+
_load_library(f"{library}.so", __variant__ == "docs")
7789

7890
try:
7991
# Trigger meta operator registrations

fbgemm_gpu/setup.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def from_args(cls, argv: List[str]):
5252
parser.add_argument(
5353
"--package_variant",
5454
type=str,
55-
choices=["cpu", "cuda", "rocm", "genai"],
55+
choices=["docs", "cpu", "cuda", "rocm", "genai"],
5656
default="cuda",
5757
help="The FBGEMM_GPU variant to build.",
5858
)
@@ -270,7 +270,16 @@ def _get_cxx11_abi():
270270
# https://stackoverflow.com/questions/44284275/passing-compiler-options-in-cmake-command-line
271271
cxx_flags.extend(["-DTORCH_USE_CUDA_DSA", "-DTORCH_USE_HIP_DSA"])
272272

273-
if self.args.package_variant == "cpu":
273+
if self.args.package_variant in ["docs", "cpu"]:
274+
# NOTE: The docs variant is a fake variant that is effectively the
275+
# cpu variant, but marks __VARIANT__ as "docs" instead of "cpu".
276+
#
277+
# This minor change lets the library loader know not throw
278+
# exceptions on failed load, which is the workaround for a bug in
279+
# the Sphinx documentation generation process, see:
280+
#
281+
# https://github.com/pytorch/FBGEMM/pull/3477
282+
# https://github.com/pytorch/FBGEMM/pull/3717
274283
print("[SETUP.PY] Building the CPU-ONLY variant of FBGEMM_GPU ...")
275284
cmake_args.append("-DFBGEMM_CPU_ONLY=ON")
276285

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# Build the code
3030
cd ..
3131
prepare_fbgemm_gpu_build $BUILD_ENV
32-
build_fbgemm_gpu_install $BUILD_ENV cpu
32+
build_fbgemm_gpu_install $BUILD_ENV docs
3333
3434
# Build the docs
3535
cd docs

0 commit comments

Comments
 (0)