Skip to content

Commit 443b4b7

Browse files
Copilotwindreamer
andcommitted
Fix docstrings: replace old-style typing constructs with modern Python 3.10+ equivalents (#2)
* Fix docstrings to Google style format aligned with type hints * Fix docformatter lint: remove extra blank line before closing triple-quote in api.py * Replace old-style Dict/List/Optional type references in docstrings * Fix docstrings to conform with Google Style and use modern Python types * Fix remaining outdated type hints in docstrings (List/Dict/Tuple/Union/Optional) * Fix invalid dict() examples in vl/engine.py docstrings - use dict literals with code blocks Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: windreamer <572167+windreamer@users.noreply.github.com>
1 parent b4a3cbc commit 443b4b7

46 files changed

Lines changed: 258 additions & 239 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

autotest/utils/config_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_func_config_list(backend: str,
5151
func_type: Test func type filter, default: func
5252
extra: extra config to update in each run config dict
5353
Returns:
54-
List[Dict]: All valid run config dicts
54+
list[dict]: All valid run config dicts
5555
"""
5656
config = get_config()
5757
device = config.get('device', 'cuda')
@@ -228,7 +228,7 @@ def get_model_list(config: dict,
228228
model_type: Model type, default: chat_model
229229
func_type: Test func type filter, default: func
230230
Returns:
231-
List[str]: Base models + quantization extended models
231+
list[str]: Base models + quantization extended models
232232
"""
233233
model_config_key = f'{backend}_{model_type}'
234234
all_models = []

lmdeploy/api.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def pipeline(model_path: str,
1919
max_log_len: int | None = None,
2020
speculative_config: SpeculativeConfig | None = None,
2121
**kwargs):
22-
"""
22+
"""Create a pipeline for inference.
23+
2324
Args:
2425
model_path: the path of a model. It could be one of the following options:
2526
@@ -34,14 +35,17 @@ def pipeline(model_path: str,
3435
on huggingface.co, such as ``internlm/internlm-chat-7b``,
3536
``Qwen/Qwen-7B-Chat``, ``baichuan-inc/Baichuan2-7B-Chat``
3637
and so on.
37-
backend_config: backend
38-
config instance. Default to None.
39-
chat_template_config: chat template configuration.
40-
Default to None.
38+
backend_config: backend config instance. Default to None.
39+
chat_template_config: chat template configuration. Default to None.
4140
log_level: set log level whose value among [``CRITICAL``, ``ERROR``,
4241
``WARNING``, ``INFO``, ``DEBUG``]
4342
max_log_len: Max number of prompt characters or prompt tokens
44-
being printed in log
43+
being printed in log.
44+
speculative_config: speculative decoding configuration.
45+
**kwargs: additional keyword arguments passed to the pipeline.
46+
47+
Returns:
48+
Pipeline: a pipeline instance for inference.
4549
4650
Examples:
4751
@@ -62,8 +66,7 @@ def pipeline(model_path: str,
6266
im = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg')
6367
response = pipe([('describe this image', [im])])
6468
print(response)
65-
66-
""" # noqa E501
69+
""" # noqa E501
6770

6871
return Pipeline(model_path,
6972
backend_config=backend_config,
@@ -106,11 +109,13 @@ def client(api_server_url: str = 'http://0.0.0.0:23333', api_key: str | None = N
106109
107110
Args:
108111
api_server_url: communicating address ``http://<ip>:<port>`` of
109-
api_server
112+
api_server.
110113
api_key: api key. Default to None, which means no
111114
api key will be used.
112-
Return:
113-
Chatbot for LLaMA series models with turbomind as inference engine.
115+
116+
Raises:
117+
NotImplementedError: This function has been deprecated and removed.
118+
Use ``from lmdeploy.serve import APIClient`` instead.
114119
"""
115120
raise NotImplementedError("The 'client' function is no longer available. This function has been deprecated. "
116121
' Please use "from lmdeploy.serve import APIClient" instead.')

lmdeploy/cli/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ def get_lora_adapters(adapters: list[str]):
4343
"""Parse lora adapers from cli input.
4444
4545
Args:
46-
adapters (List[str]): CLI input string of lora adapter path(s).
46+
adapters (list[str]): CLI input string of lora adapter path(s).
4747
4848
Returns:
49-
Dict[str,str] or None: Parsed lora adapter path(s).
49+
dict[str, str] | None: Parsed lora adapter path(s).
5050
"""
5151
if not adapters:
5252
return None

lmdeploy/lite/apis/calibrate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def _prepare_for_calibrate(model: nn.Module,
9595
----------
9696
model : nn.Module
9797
The PyTorch model to prepare for calibration.
98-
layer_type : Union[str, Type]
98+
layer_type : str | type
9999
The type of the layer to be moved to CPU. Can be either a string of
100100
class name or the class type itself.
101101
head_name : str, optional

lmdeploy/lite/quantization/calibration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def __init__(self,
4343
Args:
4444
model (nn.Module): Model to be calibrated.
4545
tokenizer (PreTrainedTokenizer): Tokenizer of the given model.
46-
layer_type (Union[str, type]): Type of the layers to be observed.
47-
norm_type (Union[str, type]): Norm type used in the model.
46+
layer_type (str | type): Type of the layers to be observed.
47+
norm_type (str | type): Norm type used in the model.
4848
batch_size (int): The batch size for running the calib samples.
4949
Low GPU mem requires small batch_size. Large batch_size
5050
reduces the calibration time while costs more VRAM.
@@ -204,7 +204,7 @@ def export(self, out_dir):
204204
to specified directory.
205205
206206
Args:
207-
out_dir (Union[str, Path]): The directory path where the stats
207+
out_dir (str | Path): The directory path where the stats
208208
will be saved.
209209
"""
210210

@@ -377,7 +377,7 @@ def export(self, out_dir):
377377
to specified directory.
378378
379379
Args:
380-
out_dir (Union[str, Path]): The directory path where the stats
380+
out_dir (str | Path): The directory path where the stats
381381
will be saved.
382382
"""
383383
inputs_stats = {

lmdeploy/lite/quantization/weight/quantizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class WeightQuantizer(GlobalAvailMixin):
3131
use min-max scaling.
3232
granularity (str): The granularity of quantization. Available options
3333
are 'per_channel', 'per_tensor', and 'per_group'.
34-
group_size (Optional[int]): If using 'per_group' quantization, this is
34+
group_size (int | None): If using 'per_group' quantization, this is
3535
the number of channels in each group.
3636
3737
Example:
@@ -108,7 +108,7 @@ def quant(self, weight: torch.Tensor, qparams: QParams | None = None, real: bool
108108
Args:
109109
weight (torch.Tensor): The weight tensor with shape
110110
(out_features, in_features).
111-
qparams (Optional[QParams]): A namedtuple containing 'scales'
111+
qparams (QParams | None): A namedtuple containing 'scales'
112112
and 'zero_points'.
113113
real (bool): If True, return the tensor with quantized type.
114114

lmdeploy/lite/utils/batch_split.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ def split_decoder_layer_inputs(batch_size, *args: torch.Tensor | Any,
1010
elements.
1111
1212
Args:
13-
*args (Union[torch.Tensor, Any]): Positional arguments which could
13+
*args (torch.Tensor | Any): Positional arguments which could
1414
be a mix of tensors and other types.
15-
**kwargs (Union[torch.Tensor, Any]): Keyword arguments which could
15+
**kwargs (torch.Tensor | Any): Keyword arguments which could
1616
be a mix of tensors and other types.
1717
1818
Returns:
19-
Tuple[List[List[Any]], List[Dict[str, Any]]]: A tuple containing two
19+
tuple[list[list[Any]], list[dict[str, Any]]]: A tuple containing two
2020
lists, one for positional arguments, one for keyword arguments.
2121
Each list contains individual elements from the batch.
2222
"""
@@ -63,7 +63,7 @@ def concat_decoder_layer_outputs(batch_outputs: list[Any]) -> Any:
6363
batched output.
6464
6565
Args:
66-
batch_outputs (List[Any]): A list, where each tuple
66+
batch_outputs (list[Any]): A list, where each tuple
6767
represents the output from an individual element in the batch.
6868
6969
Returns:

lmdeploy/lite/utils/global_avail.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def global_available(self, key: str | nn.Module = 'default', group: str = 'defau
1313
"""Make the instance globally available.
1414
1515
Args:
16-
key (Union[str, nn.Module], optional): Key to save the instance.
16+
key (str | nn.Module, optional): Key to save the instance.
1717
Defaults to 'default'.
1818
group (str, optional): Group to save the instance.
1919
Defaults to 'default'.
@@ -29,7 +29,7 @@ def _save_instance(cls,
2929
3030
Args:
3131
instance (GlobalAvailMixin): Instance to save.
32-
key (Union[str, nn.Module], optional): Key to save the instance.
32+
key (str | nn.Module, optional): Key to save the instance.
3333
Defaults to 'default'.
3434
group (str, optional): Group to save the instance.
3535
Defaults to 'default'.
@@ -45,13 +45,13 @@ def find(cls, key: str | nn.Module = 'default', group: str = 'default') -> Union
4545
"""Find an instance by its key and group.
4646
4747
Args:
48-
key (Union[str, nn.Module], optional): Key of the instance.
48+
key (str | nn.Module, optional): Key of the instance.
4949
Defaults to 'default'.
5050
group (str, optional): Group of the instance.
5151
Defaults to 'default'.
5252
5353
Returns:
54-
Union[None, GlobalAvailMixin]: The found instance, or None if
54+
None | GlobalAvailMixin: The found instance, or None if
5555
it does not exist.
5656
"""
5757
return cls._instances.get(group, {}).get(key)
@@ -64,7 +64,7 @@ def find_group(cls, group: str) -> dict[str | nn.Module, 'GlobalAvailMixin']:
6464
group (str): Group of the instances.
6565
6666
Returns:
67-
Dict[Union[str, nn.Module], GlobalAvailMixin]: All instances in
67+
dict[str | nn.Module, GlobalAvailMixin]: All instances in
6868
the group.
6969
"""
7070
return cls._instances.get(group, {})

lmdeploy/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class RequestLogger:
1212
exceed a specified maximum length.
1313
1414
Args:
15-
max_log_len (Optional[int]): The maximum length of the log entries.
15+
max_log_len (int | None): The maximum length of the log entries.
1616
If None, no maximum length is enforced.
1717
"""
1818

lmdeploy/messages.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ class GenerationConfig:
5151
random_seed: Seed used when sampling a token
5252
stop_words: Words that stop generating further tokens
5353
bad_words: Words that the engine will never generate
54-
stop_token_ids: List of tokens that stop the generation
54+
stop_token_ids: list of tokens that stop the generation
5555
when they are generated. The returned output will not contain
5656
the stop tokens.
57-
bad_token_ids: List of tokens that the engine will never
57+
bad_token_ids: list of tokens that the engine will never
5858
generate.
5959
min_new_tokens: The minimum numbers of tokens to generate,
6060
ignoring the number of tokens in the prompt.
@@ -475,16 +475,13 @@ class Response:
475475
generate_token_len: the response token length.
476476
input_token_len: the input prompt token length. Note that it may
477477
contains chat template part.
478-
session_id: the id for running the session.
479478
finish_reason: the reason the model stopped
480479
generating tokens. This will be 'stop' if the model hit a natural
481480
stop point or a provided stop sequence, 'length' if the maximum
482481
number of tokens specified in the request was reached.
483-
token_ids:: the output token ids.
484-
logprobs:: the top logprobs for each output
485-
position.
486-
index: it refers to the position index of the input request
487-
batch
482+
token_ids: the output token ids.
483+
logprobs: the top logprobs for each output position.
484+
index: it refers to the position index of the input request batch.
488485
"""
489486
text: str
490487
generate_token_len: int
@@ -605,7 +602,7 @@ class RequestMetrics:
605602
606603
Attributes:
607604
token_timestamp: A wall-clock time when a token is generated.
608-
engine_events: List of engine events during inference.
605+
engine_events: list of engine events during inference.
609606
"""
610607
token_timestamp: float = 0.0
611608
engine_events: list[EngineEvent] = field(default_factory=list)

0 commit comments

Comments
 (0)