Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jun 10, 2024
1 parent 665e124 commit 73da1e5
Show file tree
Hide file tree
Showing 53 changed files with 153 additions and 95 deletions.
16 changes: 10 additions & 6 deletions applications/ColossalChat/coati/dataset/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,19 @@ def __call__(self, instances: Sequence[Dict[str, List[int]]]) -> Dict[str, torch

# `List[torch.Tensor]`
batch_input_ids = [
torch.LongTensor(instance["input_ids"][: self.max_length])
if len(instance["input_ids"]) > self.max_length
else torch.LongTensor(instance["input_ids"])
(
torch.LongTensor(instance["input_ids"][: self.max_length])
if len(instance["input_ids"]) > self.max_length
else torch.LongTensor(instance["input_ids"])
)
for instance in instances
]
batch_labels = [
torch.LongTensor(instance["labels"][: self.max_length])
if len(instance["labels"]) > self.max_length
else torch.LongTensor(instance["labels"])
(
torch.LongTensor(instance["labels"][: self.max_length])
if len(instance["labels"]) > self.max_length
else torch.LongTensor(instance["labels"])
)
for instance in instances
]
if self.tokenizer.padding_side == "right":
Expand Down
1 change: 1 addition & 0 deletions applications/ColossalChat/coati/models/loss.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
loss functions
"""

from typing import Optional, Tuple

import torch
Expand Down
1 change: 1 addition & 0 deletions applications/ColossalChat/coati/models/reward_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
reward model
"""

from typing import Optional

import torch
Expand Down
1 change: 1 addition & 0 deletions applications/ColossalChat/coati/trainer/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Training utilities for Coati.
"""

from typing import Any

import torch
Expand Down
14 changes: 12 additions & 2 deletions applications/ColossalEval/colossal_eval/dataset/agieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def get_prompt(line: Dict, dataset_name: str, logger: DistributedLogger) -> Dict
option_string = "ABCDEFG"
count = len(line["options"])

input = "问题:" + line["question"] + " " + "从以下选项中选择:" + " ".join(line["options"]) + "\n" + "答案:"
input = (
"问题:" + line["question"] + " " + "从以下选项中选择:" + " ".join(line["options"]) + "\n" + "答案:"
)

all_classes = list(option_string[0:count])

Expand Down Expand Up @@ -150,7 +152,15 @@ def combine_prompt(prompt_path, dataset_name, load_explanation=True, chat_mode=F
)
elif dataset_name in chinese_qa_datasets:
question_input = (
"问题:" + passage + " " + question + "\n" + "从以下选项中选择:" + " ".join(options) + "\n" + "答案:{}".format(label)
"问题:"
+ passage
+ " "
+ question
+ "\n"
+ "从以下选项中选择:"
+ " ".join(options)
+ "\n"
+ "答案:{}".format(label)
)
elif dataset_name in english_cloze_datasets:
question_input = "Question: ".format(idx + 1) + question + "\n" + "Answer: {}".format(answer)
Expand Down
6 changes: 5 additions & 1 deletion applications/ColossalEval/colossal_eval/dataset/ceval.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@
"urban_and_rural_planner": ["Urban and Rural Planner", "注册城乡规划师", "Other"],
"accountant": ["Accountant", "注册会计师", "Other"],
"fire_engineer": ["Fire Engineer", "注册消防工程师", "Other"],
"environmental_impact_assessment_engineer": ["Environmental Impact Assessment Engineer", "环境影响评价工程师", "Other"],
"environmental_impact_assessment_engineer": [
"Environmental Impact Assessment Engineer",
"环境影响评价工程师",
"Other",
],
"tax_accountant": ["Tax Accountant", "税务师", "Other"],
"physician": ["Physician", "医师资格", "Other"],
}
Expand Down
8 changes: 5 additions & 3 deletions applications/ColossalEval/colossal_eval/dataset/mtbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ def load(path: str, logger: DistributedLogger, few_shot: bool) -> List[Dict]:
"instruction": question["turns"],
"input": "",
"output": [],
"target": [""] * turn_number
if question["question_id"] not in reference
else reference[question["question_id"]],
"target": (
[""] * turn_number
if question["question_id"] not in reference
else reference[question["question_id"]]
),
}

if category in dataset["test"]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def _get_choices_indices(self, language: str):
self.indices_for_choices[0].append(
self.tokenizer(f"Answer: {choice}", add_special_tokens=False).input_ids[-1]
)
self.indices_for_choices[1].append(self.tokenizer(f"答案:{choice}", add_special_tokens=False).input_ids[-1])
self.indices_for_choices[1].append(
self.tokenizer(f"答案:{choice}", add_special_tokens=False).input_ids[-1]
)

def _load_tokenizer(self, path: str, tokenizer_path: Optional[str], tokenizer_kwargs: dict):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
https://github.com/langchain-ai/langchain
The original code is licensed under the MIT license.
"""

from __future__ import annotations

import copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
https://github.com/langchain-ai/langchain
The original code is licensed under the MIT license.
"""

import copy
from typing import Any, Mapping, Optional, Protocol

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
https://github.com/langchain-ai/langchain
The original code is licensed under the MIT license.
"""

import copy
from typing import Any, List

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Class for loading table type data. please refer to Pandas-Input/Output for file format details.
"""


import glob
import os

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
print(resp) # super-heavyweight awesome-natured yawning Australian creature!
"""

import json
from typing import Any, Mapping

Expand Down
1 change: 1 addition & 0 deletions applications/ColossalQA/colossalqa/local/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
logger.info(llm(TEST_PROMPT_CHATGLM, max_new_tokens=100), verbose=True)
"""

from typing import Any, List, Mapping, Optional

import torch
Expand Down
1 change: 1 addition & 0 deletions applications/ColossalQA/colossalqa/local/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Generation utilities
"""

import json
from typing import List

Expand Down
1 change: 1 addition & 0 deletions applications/ColossalQA/colossalqa/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Implement a memory class for storing conversation history
Support long term and short term memory
"""

from typing import Any, Dict, List

from colossalqa.chain.memory.summary import ConversationSummaryMemory
Expand Down
1 change: 1 addition & 0 deletions applications/ColossalQA/colossalqa/mylogging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Class for logging with extra control for debugging
"""

import logging


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Script for Chinese retrieval based conversation system backed by ChatGLM
"""

from typing import Tuple

from colossalqa.chain.retrieval_qa.base import RetrievalQA
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Multilingual retrieval based conversation system
"""

from typing import List

from colossalqa.data_loader.document_loader import DocumentLoader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Script for Chinese retrieval based conversation system backed by ChatGLM
"""

from typing import Tuple

from colossalqa.chain.retrieval_qa.base import RetrievalQA
Expand Down
1 change: 1 addition & 0 deletions applications/ColossalQA/colossalqa/retriever.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Code for custom retriver with incremental update
"""

import copy
import hashlib
import os
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Code for Chinese text splitter
"""

from typing import Any, List, Optional

from colossalqa.text_splitter.utils import get_cleaned_paragraph
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Script for English retrieval based conversation system backed by LLaMa2
"""

import argparse
import os

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Script for English retrieval based conversation system backed by LLaMa2
"""

import argparse
import json
import os
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Script for Chinese retrieval based conversation system backed by ChatGLM
"""

import argparse
import os

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Script for English retrieval based conversation system backed by LLaMa2
"""

import argparse
import os

Expand Down
20 changes: 11 additions & 9 deletions colossalai/auto_parallel/meta_profiler/meta_registry/conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,22 @@ def convnd_meta_info(*args, **kwargs) -> Tuple[TrainCycleItem, TrainCycleItem, L
# NOTE: currently in SPMD solver we always believe that there will be a new tensor created in forward
fwd_memory_cost = MemoryCost(
activation=compute_size_in_bytes([input_tensor, output_tensor]),
parameter=compute_size_in_bytes([weight_tensor, bias_tensor])
if has_bias
else compute_size_in_bytes(weight_tensor),
parameter=(
compute_size_in_bytes([weight_tensor, bias_tensor]) if has_bias else compute_size_in_bytes(weight_tensor)
),
temp=0,
buffer=0,
)

bwd_memory_cost = MemoryCost(
activation=compute_size_in_bytes([input_tensor, weight_tensor, bias_tensor])
if has_bias
else compute_size_in_bytes([input_tensor, weight_tensor]),
parameter=compute_size_in_bytes([weight_tensor, bias_tensor])
if has_bias
else compute_size_in_bytes(weight_tensor),
activation=(
compute_size_in_bytes([input_tensor, weight_tensor, bias_tensor])
if has_bias
else compute_size_in_bytes([input_tensor, weight_tensor])
),
parameter=(
compute_size_in_bytes([weight_tensor, bias_tensor]) if has_bias else compute_size_in_bytes(weight_tensor)
),
temp=0,
buffer=0,
)
Expand Down
12 changes: 6 additions & 6 deletions colossalai/inference/batch_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,16 @@ def add_seqs(
self._sequences_dict[seq.request_id] = seq
self._sequences_indexes[seq.request_id] = self._current_batch_size + i
# TODO external (rename): modify Sequence.sentence_len to seq_len
self._sequence_lengths[
self._current_batch_size : self._current_batch_size + num_seqs_to_add
] = torch.tensor([seq.sentence_len for seq in seqs[:num_seqs_to_add]], dtype=torch.int32)
self._sequence_lengths[self._current_batch_size : self._current_batch_size + num_seqs_to_add] = (
torch.tensor([seq.sentence_len for seq in seqs[:num_seqs_to_add]], dtype=torch.int32)
)
# NOTE block tables to be updated by kvcache manager
block_tables = self._block_tables[self._current_batch_size : self._current_batch_size + num_seqs_to_add]
if alloc_block_tables is not None:
# copy block ids from provided block tables
self._block_tables[
self._current_batch_size : self._current_batch_size + num_seqs_to_add
] = alloc_block_tables
self._block_tables[self._current_batch_size : self._current_batch_size + num_seqs_to_add] = (
alloc_block_tables
)
elif alloc_block_tables_fn:
alloc_block_tables_fn(
block_tables,
Expand Down
17 changes: 10 additions & 7 deletions colossalai/inference/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Our config contains various options for inference optimization, it is a unified API that wraps all the configurations for inference.
"""

import logging
from abc import ABC, abstractmethod
from dataclasses import dataclass, fields
Expand Down Expand Up @@ -82,9 +83,9 @@ class InputMetaData(RPC_PARAM):
dtype: torch.dtype = torch.float32
use_spec_dec: bool = False
num_tokens_to_verify: int = 0
batch_token_ids: Optional[
List[List[int]]
] = None # for `repetition_penalty`, `no_repeat_ngram_size` in sampler process
batch_token_ids: Optional[List[List[int]]] = (
None # for `repetition_penalty`, `no_repeat_ngram_size` in sampler process
)

def to_rpc_param(self) -> Dict[str, any]:
return {
Expand Down Expand Up @@ -202,9 +203,9 @@ class InferenceConfig(RPC_PARAM):
prompt_template: Optional[str] = None
do_sample: bool = False
beam_width: int = 1 # TODO: beam search is not support for now
prefill_ratio: Optional[
float
] = 1.2 # the ratio of prefill sequences to decoding sequences, we do prefill step once the actual value exceeds ratio
prefill_ratio: Optional[float] = (
1.2 # the ratio of prefill sequences to decoding sequences, we do prefill step once the actual value exceeds ratio
)
pad_input: bool = False
early_stopping: Optional[bool] = False
top_k: Optional[int] = 50
Expand Down Expand Up @@ -234,7 +235,9 @@ class InferenceConfig(RPC_PARAM):
high_precision: Optional[bool] = False

# cuda_graph
use_cuda_graph: bool = False # NOTE only when we have the graph for specific decoding batch size can we use the cuda graph for inference
use_cuda_graph: bool = (
False # NOTE only when we have the graph for specific decoding batch size can we use the cuda graph for inference
)
max_context_len_to_capture: int = 512

# StreamingLLM (sliding window attention with attention sinks)
Expand Down
1 change: 0 additions & 1 deletion colossalai/inference/core/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@


class InferenceEngine:

"""
InferenceEngine which manages the inference process..
Expand Down
1 change: 0 additions & 1 deletion colossalai/inference/core/rpc_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def run_server(host, port, event: mp.Event = None):


class RPCInferenceEngine(InferenceEngine):

"""
InferenceEngine which manages the inference process..
Expand Down
1 change: 0 additions & 1 deletion colossalai/inference/executor/rpc_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@


class rpcWorkerService(rpyc.Service):

"""
Execute the computation tasks and manage its own kv cache
Expand Down
8 changes: 5 additions & 3 deletions colossalai/inference/kv_cache/kvcache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,11 @@ def allocate_context_from_block_tables(self, block_tables: torch.Tensor, context
block.add_ref()
self._allocate_on_block(
block,
block.block_size
if context_lengths[i] % block.block_size == 0
else context_lengths[i].item() % block.block_size,
(
block.block_size
if context_lengths[i] % block.block_size == 0
else context_lengths[i].item() % block.block_size
),
)
for block_id in alloc_block_ids:
if block_id in alloc_block_ids[last_block_locs]:
Expand Down
Loading

0 comments on commit 73da1e5

Please sign in to comment.