Skip to content

Commit 4c2848b

Browse files
authored
Small cleanup. (#1560)
Using a single `os.getenv` statement instead of multiple. Should make truthful values easier to catch In the end didn't move towards full CLI because modifying globals in Python is error prone (depends on code import order). Added an error when mamba is launched with TP. # What does this PR do? <!-- Congratulations! You've made it this far! You're not quite done yet though. Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution. Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change. Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost. --> <!-- Remove if not applicable --> Fixes # (issue) ## Before submitting - [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). - [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests), Pull Request section? - [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link to it if that's the case. - [ ] Did you make sure to update the documentation with your changes? Here are the [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation). - [ ] Did you write any new necessary tests? ## Who can review? Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR. <!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @ @OlivierDehaene OR @Narsil -->
1 parent d6b0fb9 commit 4c2848b

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

server/text_generation_server/models/flash_causal_lm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
BLOCK_SIZE,
2929
)
3030
from text_generation_server.pb import generate_pb2
31-
from text_generation_server.models.globals import MEM_POOL
31+
from text_generation_server.models.globals import MEM_POOL, ENABLE_CUDA_GRAPHS
3232
from text_generation_server.utils import StoppingCriteria, HeterogeneousNextTokenChooser
3333
from text_generation_server.utils.dist import MEMORY_FRACTION
3434

@@ -793,7 +793,7 @@ def warmup(self, batch: FlashCausalLMBatch):
793793
self.device,
794794
)
795795

796-
if os.getenv("ENABLE_CUDA_GRAPHS", "False") == "True":
796+
if ENABLE_CUDA_GRAPHS:
797797
try:
798798
logger.info("Experimental support for Cuda Graphs is enabled")
799799
# Warmup cuda graphs
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
import torch
2+
import os
23

34
MEM_POOL = torch.cuda.graph_pool_handle()
5+
# This is overridden by the cli
6+
ENABLE_CUDA_GRAPHS = os.getenv("ENABLE_CUDA_GRAPHS", "false").lower() in {"1", "true"}

server/text_generation_server/models/mamba.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
weight_files,
1414
Weights,
1515
)
16-
from text_generation_server.models.globals import MEM_POOL
16+
from text_generation_server.models.globals import ENABLE_CUDA_GRAPHS, MEM_POOL
1717
import time
1818
from text_generation_server.models.custom_modeling.mamba_modeling import MambaModel, InferenceParams
1919
from text_generation_server.models import Model
@@ -377,7 +377,9 @@ def __init__(
377377
dtype: Optional[torch.dtype] = None,
378378
trust_remote_code: bool = False,
379379
):
380-
self.process_group, _rank, _world_size = initialize_torch_distributed()
380+
self.process_group, _rank, world_size = initialize_torch_distributed()
381+
if world_size > 1:
382+
raise RuntimeError("Mamba does not support Tensor Parallelism (TP)")
381383
self.cuda_graphs = {}
382384
if torch.cuda.is_available():
383385
device = torch.device("cuda")
@@ -427,7 +429,7 @@ def batch_type(self) -> Type[MambaBatch]:
427429

428430
def warmup(self, batch) -> Optional[int]:
429431
# TODO: implement warmup for Mamba if needed
430-
if os.getenv("ENABLE_CUDA_GRAPHS", "False") == "True":
432+
if ENABLE_CUDA_GRAPHS:
431433
if self.speculate is None or self.speculate == 0:
432434
try:
433435
logger.info("Experimental support for Cuda Graphs is enabled")

0 commit comments

Comments
 (0)