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 Apr 8, 2024
1 parent 57a9574 commit f63a248
Show file tree
Hide file tree
Showing 70 changed files with 547 additions and 604 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,4 @@ Copyright 2021- HPC-AI Technology Inc. All rights reserved.
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
6 changes: 4 additions & 2 deletions applications/Chat/benchmarks/benchmark_opt_lora_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ def main(args):
if args.strategy == "ddp":
strategy = DDPStrategy()
elif args.strategy == "colossalai_gemini":
strategy = GeminiStrategy(placement_policy="static",initial_scale=2**5)
strategy = GeminiStrategy(placement_policy="static", initial_scale=2**5)
elif args.strategy == "colossalai_gemini_cpu":
strategy = GeminiStrategy(placement_policy="static", offload_optim_frac=1.0, offload_param_frac=1.0, initial_scale=2**5)
strategy = GeminiStrategy(
placement_policy="static", offload_optim_frac=1.0, offload_param_frac=1.0, initial_scale=2**5
)
elif args.strategy == "colossalai_zero2":
strategy = LowLevelZeroStrategy(stage=2, placement_policy="cuda")
elif args.strategy == "colossalai_zero2_cpu":
Expand Down
16 changes: 13 additions & 3 deletions applications/Chat/coati/dataset/sft_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,21 @@ def _preprocess(
"""Preprocess the data by tokenizing."""
sequences = [s + t + tokenizer.eos_token for s, t in zip(sources, targets)]
sequences_token = tokenizer(
sequences, max_length=max_length, padding="max_length", truncation=True, return_tensors="pt", add_special_tokens=False
sequences,
max_length=max_length,
padding="max_length",
truncation=True,
return_tensors="pt",
add_special_tokens=False,
)

sources_token = tokenizer(
sources, max_length=max_length, padding="max_length", truncation=True, return_tensors="pt", add_special_tokens=False
sources,
max_length=max_length,
padding="max_length",
truncation=True,
return_tensors="pt",
add_special_tokens=False,
)

assert sequences_token["attention_mask"].dim() == 2, "seq2seq model should be preprocessed differently"
Expand All @@ -66,7 +76,7 @@ def _preprocess(
if tokenizer.padding_side == "right":
# |prompt|completion|eos|pad|
labels[i][:source_len] = IGNORE_INDEX
if pad_len>0:
if pad_len > 0:
labels[i][-pad_len:] = IGNORE_INDEX
elif tokenizer.padding_side == "left":
# |pad|prompt|completion|eos|
Expand Down
1 change: 0 additions & 1 deletion applications/Chat/coati/models/base/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ def forward(
"""Returns model output."""
output = self.model(input_ids, attention_mask=attention_mask, **model_kwargs)
return output

4 changes: 3 additions & 1 deletion applications/Chat/coati/ray/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def get_strategy_from_args(strategy: str):
elif strategy == "colossalai_zero2":
strategy_ = LowLevelZeroStrategy(stage=2, placement_policy="cuda")
elif strategy == "colossalai_gemini_cpu":
strategy_ = GeminiStrategy(placement_policy="static", offload_optim_frac=1.0, offload_param_frac=1.0, initial_scale=2**5)
strategy_ = GeminiStrategy(
placement_policy="static", offload_optim_frac=1.0, offload_param_frac=1.0, initial_scale=2**5
)
elif strategy == "colossalai_zero2_cpu":
strategy_ = LowLevelZeroStrategy(stage=2, placement_policy="cpu")
else:
Expand Down
3 changes: 2 additions & 1 deletion applications/Chat/coati/trainer/strategies/ddp.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,17 @@ def save_pretrained(

model_path = os.path.join(path, "pytorch_model.bin")
self.save_model(model, model_path, shard=shard)

def _replace_keys(model_path: str, replace_fn: Callable):
state_dict = torch.load(model_path, map_location="cpu")
state_dict = {replace_fn(k): v for k, v in state_dict.items()}
torch.save(state_dict, model_path)

# FIXME: save_model would add "model." prefix to keys of pytorch_model.bin
# HACK: rename keys of pytorch_model.bin
if dist.get_rank() == 0:
_replace_keys(model_path, lambda k: k.replace("model.", "", 1))


def get_model_state_dict_shard(self, model: nn.Module, **config):
# TODO: implement sharding on naive strategy
model = self.unwrap_model(model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def main(args):
if args.strategy == "ddp":
strategy = DDPStrategy()
elif args.strategy == "colossalai_gemini":
strategy = GeminiStrategy(placement_policy="static", offload_optim_frac=1.0, offload_param_frac=1.0, initial_scale=2**5)
strategy = GeminiStrategy(
placement_policy="static", offload_optim_frac=1.0, offload_param_frac=1.0, initial_scale=2**5
)
elif args.strategy == "colossalai_zero2":
strategy = LowLevelZeroStrategy(stage=2, placement_policy="cpu")
else:
Expand Down
2 changes: 1 addition & 1 deletion applications/Chat/examples/train_sft.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ torchrun --standalone --nproc_per_node=4 train_sft.py \
--accumulation_steps 8 \
--lr 2e-5 \
--max_datasets_size 512 \
--max_epochs 1
--max_epochs 1
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

import numpy as np
import torch
from transformers import LlamaTokenizer, LlamaForCausalLM
from transformers import LlamaForCausalLM, LlamaTokenizer

from colossalai.logging import get_dist_logger


logger = get_dist_logger()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from typing import Any, Dict, Tuple, Union

import torch
from torch.optim.optimizer import Optimizer
from torch.optim.lr_scheduler import _LRScheduler
from torch.optim.optimizer import Optimizer

from colossalai.booster import Booster
from colossalai.cluster import DistCoordinator
Expand Down
6 changes: 3 additions & 3 deletions applications/Colossal-LLaMA-2/docs/example_13b.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if __name__ == '__main__':
model.to(device)

tokenizer = AutoTokenizer.from_pretrained("hpcai-tech/Colossal-LLaMA-2-13b-base")

question = "xxx" # Your question.
prompt = (f"请对下面的问题,给出准确、可靠、安全的回答\n"
f"{question}"
Expand Down Expand Up @@ -111,7 +111,7 @@ The Colossal-AI team has conducted comprehensive evaluation for safety and value
| 整车热管理主要包括什么内容 | 整车热管理主要包括:1、发动机冷却系统;2、散热系统;3、空调冷却系统;4、采暖系统;5、动力转向器冷却系统;6、润滑油冷却系统;7、变速箱冷却系统;8、燃油冷却系统;9、冷却系统排放液系统。 |
| 简述下汽车空调-热泵循环系统的原理 | 汽车空调系统主要有三种形式,其中热泵循环系统是其中的一种。其原理是利用发动机排放的热量,通过压缩机将冷媒压缩成高温高压的状态,然后通过冷却器释放到空气中,吸收周围的热量,再通过膨胀阀释放到蒸发器中,蒸发器在压缩机的作用下将冷媒压缩成高温高压的状态,再次释放到空气中,从而实现制冷的效果。 |

#### Finance
#### Finance
| Question | <center>Colossal-LLaMA-2-13b-base</center> |
| :------: | :----------------------- |
| 如何看待当前提前还贷热 | 提前还贷是一种常见的还贷方式,在市场中存在着许多的因素和影响,需要具体分析当前的经济形势和人们心理状况的影响。提前还贷可以帮助借款人早日摆脱债务负担,但也存在一些风险和不确定性。从经济形势来看,当前利率下探、还款压力减轻等因素可能会导致一部分借款人提前还贷。此外,一些购房者可能会受到市场不景气的影响,担心未来房产价值会下降,因此提前还贷以避免资产贬值。从借款人心理状况来看,提前还贷也可能会由于借款人对未来经济预期的不确定性而产生压力和不满。因此,提前还贷并不能一概而论,需要根据具体情况进行分析。如果提前还贷对借款人的经济情况和未来规划造成不利影响,建议谨慎考虑是否要提前还贷。|
Expand Down Expand Up @@ -150,4 +150,4 @@ The Colossal-AI team has conducted comprehensive evaluation for safety and value


## Conclusion
The Colossal-AI team's advanced 13B model, compared to the 7B version, features a refined data structure categorizing information into informative, functional, and memory replay data. Informative data is intricately subdivided into major categories, each further segmented for precise control. Concurrently, data scale across domains is expanded. Tailored enhancements meet community demands for large model capabilities in natural language processing tasks, ensuring proficiency during pre-training and cost-effective fine-tuning. Addressing security and values concerns, multidimensional controls are implemented, securing the baseline model and aligning it with correct values.
The Colossal-AI team's advanced 13B model, compared to the 7B version, features a refined data structure categorizing information into informative, functional, and memory replay data. Informative data is intricately subdivided into major categories, each further segmented for precise control. Concurrently, data scale across domains is expanded. Tailored enhancements meet community demands for large model capabilities in natural language processing tasks, ensuring proficiency during pre-training and cost-effective fine-tuning. Addressing security and values concerns, multidimensional controls are implemented, securing the baseline model and aligning it with correct values.
2 changes: 1 addition & 1 deletion applications/Colossal-LLaMA-2/docs/example_7b.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,4 @@ To comprehensively assess the performance of the Colossal-LLaMA-2-7B-base model,
## Conclusion
In general, the Colossal-LLaMA-2-7B-base model not only enhances its understanding of English but also exhibits significant improvements in its comprehension of Chinese. It boasts a broad spectrum of general knowledge, encompassing various fields such as food, sports, technology, literature, games, and more. Regarding text generation tasks, the Colossal-LLaMA-2-7B-base model excels in writing performance; however, its ability to generate specific formats like code, emails, tables, etc., needs enhancement due to the scarcity of relevant training data during our training phase. When compared to the Qwen-7b-base model, the Colossal-LLaMA-2-7B-base model outperforms it in answering most English questions and some Chinese questions, as demonstrated in the examples above.

Presently, the Colossal-LLaMA-2-7B-base model already exhibits some capabilities in sentiment analysis, logical reasoning, information extraction, role-play, classification, and rewriting. These capabilities are poised for further improvement in the future as part of our ongoing enhancements.
Presently, the Colossal-LLaMA-2-7B-base model already exhibits some capabilities in sentiment analysis, logical reasoning, information extraction, role-play, classification, and rewriting. These capabilities are poised for further improvement in the future as part of our ongoing enhancements.
2 changes: 1 addition & 1 deletion applications/Colossal-LLaMA-2/hostfile.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
hostname1
hostname2
hostname2
2 changes: 1 addition & 1 deletion applications/Colossal-LLaMA-2/inference_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def load_model(model_path, device="cuda", **kwargs):
model.to(device)

try:
tokenizer = AutoTokenizer.from_pretrained(model_path, padding_side='left')
tokenizer = AutoTokenizer.from_pretrained(model_path, padding_side="left")
except OSError:
raise ImportError("Tokenizer not found. Please check if the tokenizer exists or the model path is correct.")

Expand Down
1 change: 0 additions & 1 deletion applications/Colossal-LLaMA-2/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ flash-attn>=2.0.0,<=2.0.5
tqdm
sentencepiece==0.1.99
protobuf<=3.20.0

2 changes: 1 addition & 1 deletion applications/Colossal-LLaMA-2/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
0.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
from typing import Dict, List

import torch
import torch.distributed as dist
from colossal_eval import dataset, models, utils

Expand Down
Binary file modified applications/ColossalMoE/README.md
Binary file not shown.
1 change: 0 additions & 1 deletion applications/ColossalMoE/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,5 @@ def main():
print(f"[{coordinator.rank}] {outputs}")



if __name__ == "__main__":
main()
18 changes: 11 additions & 7 deletions applications/ColossalQA/colossalqa/chain/retrieval_qa/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from langchain.schema import BaseRetriever, Document
from langchain.schema.language_model import BaseLanguageModel


class CustomBaseRetrievalQA(BaseRetrievalQA):
"""Base class for question-answering chains."""

Expand Down Expand Up @@ -98,7 +99,6 @@ def _call(
for k, v in inputs.items()
if k in ["stop", "temperature", "top_k", "top_p", "max_new_tokens", "doc_prefix"]
}
answers = []
if self.combine_documents_chain.memory is not None:
buffered_history_backup, summarized_history_temp_backup = copy.deepcopy(
self.combine_documents_chain.memory.buffered_history
Expand All @@ -117,10 +117,10 @@ def _call(
) = copy.deepcopy(buffered_history_backup), copy.deepcopy(summarized_history_temp_backup)

# if rejection_trigger_keywords is not given, return the response from LLM directly
rejection_trigger_keywrods = inputs.get('rejection_trigger_keywrods', [])
rejection_trigger_keywrods = inputs.get("rejection_trigger_keywrods", [])
answer = answer if all([rej not in answer for rej in rejection_trigger_keywrods]) else None
if answer is None:
answer = inputs.get('rejection_answer', "抱歉,根据提供的信息无法回答该问题。")
if answer is None:
answer = inputs.get("rejection_answer", "抱歉,根据提供的信息无法回答该问题。")
if self.combine_documents_chain.memory is not None:
self.combine_documents_chain.memory.save_context({"question": question}, {"output": answer})

Expand Down Expand Up @@ -161,10 +161,14 @@ async def _acall(
input_documents=docs, question=question, callbacks=_run_manager.get_child(), **kwargs
)
# if rejection_trigger_keywords is not given, return the response from LLM directly
rejection_trigger_keywrods = inputs.get('rejection_trigger_keywrods', [])
answer = answer if all([rej not in answer for rej in rejection_trigger_keywrods]) or len(rejection_trigger_keywrods)==0 else None
rejection_trigger_keywrods = inputs.get("rejection_trigger_keywrods", [])
answer = (
answer
if all([rej not in answer for rej in rejection_trigger_keywrods]) or len(rejection_trigger_keywrods) == 0
else None
)
if answer is None:
answer = inputs.get('rejection_answer', "抱歉,根据提供的信息无法回答该问题。")
answer = inputs.get("rejection_answer", "抱歉,根据提供的信息无法回答该问题。")
self.combine_documents_chain.memory.save_context({"question": question}, {"output": answer})

if self.return_source_documents:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def load_data(self, path: str) -> None:
else:
# May ba a directory, we strictly follow the glob path and will not load files in subdirectories
pass

def clear(self):
"""
Clear loaded data.
Expand Down
Loading

0 comments on commit f63a248

Please sign in to comment.