Skip to content

Commit

Permalink
skip importing torch and _kernels when building docs
Browse files Browse the repository at this point in the history
  • Loading branch information
yzh119 committed Jan 31, 2024
1 parent 4b0a23e commit d5f397d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

sys.path.insert(0, os.path.abspath("../python"))
os.environ["BUILD_DOC"] = "1"

import flashinfer

Expand Down
15 changes: 11 additions & 4 deletions python/flashinfer/cascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@
import math
from typing import Optional

import torch

try:
import torch
from . import _kernels
except ImportError:
_kernels = None
except ImportError as e:
import os
import logging
if os.environ.get("BUILD_DOC", "0") == "1":
_kernels = None
logging.warning(
"Kernels are not loaded in documentation build mode."
)
else:
raise e

from .decode import (
batch_decode_with_padded_kv_cache_return_lse,
Expand Down
16 changes: 12 additions & 4 deletions python/flashinfer/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@
import math
from typing import Optional, Union

import torch

try:
import torch
from . import _kernels
except ImportError:
_kernels = None
except ImportError as e:
import os
import logging
if os.environ.get("BUILD_DOC", "0") == "1":
_kernels = None
logging.warning(
"Kernels are not loaded in documentation build mode."
)
else:
raise e


from .utils import (
RotaryMode,
Expand Down
15 changes: 11 additions & 4 deletions python/flashinfer/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@
import torch

try:
import torch
from . import _kernels
except ImportError:
_kernels = None
from .utils import TensorLayout, check_kv_layout

except ImportError as e:
import os
import logging
if os.environ.get("BUILD_DOC", "0") == "1":
_kernels = None
logging.warning(
"Kernels are not loaded in documentation build mode."
)
else:
raise e

def append_paged_kv_cache(
append_key: torch.Tensor,
Expand Down
15 changes: 11 additions & 4 deletions python/flashinfer/prefill.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@
import math
from typing import Optional

import torch

try:
import torch
from . import _kernels
except ImportError:
_kernels = None
except ImportError as e:
import os
import logging
if os.environ.get("BUILD_DOC", "0") == "1":
_kernels = None
logging.warning(
"Kernels are not loaded in documentation build mode."
)
else:
raise e

from .utils import (
RotaryMode,
Expand Down

0 comments on commit d5f397d

Please sign in to comment.