From 8b163bd8e96934a9d0db44decc3bb6b9424c8441 Mon Sep 17 00:00:00 2001 From: Tong Gao Date: Tue, 1 Aug 2023 18:19:49 +0800 Subject: [PATCH] [Feature] Several enhancements (#142) --- .pre-commit-config-zh-cn.yaml | 69 +++++++++++++++++++ .../icl_inferencer/icl_clp_inferencer.py | 4 -- opencompass/utils/lark.py | 19 +++++ requirements.txt | 2 + 4 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 .pre-commit-config-zh-cn.yaml diff --git a/.pre-commit-config-zh-cn.yaml b/.pre-commit-config-zh-cn.yaml new file mode 100644 index 00000000..7fc0922b --- /dev/null +++ b/.pre-commit-config-zh-cn.yaml @@ -0,0 +1,69 @@ +exclude: | + (?x)^( + tests/data/| + opencompass/models/internal/| + opencompass/utils/internal/| + configs/ + ) +repos: + - repo: https://gitee.com/openmmlab/mirrors-flake8 + rev: 5.0.4 + hooks: + - id: flake8 + - repo: https://gitee.com/openmmlab/mirrors-isort + rev: 5.11.5 + hooks: + - id: isort + - repo: https://gitee.com/openmmlab/mirrors-yapf + rev: v0.32.0 + hooks: + - id: yapf + - repo: https://gitee.com/openmmlab/mirrors-codespell + rev: v2.2.1 + hooks: + - id: codespell + - repo: https://gitee.com/openmmlab/mirrors-pre-commit-hooks + rev: v4.3.0 + hooks: + - id: trailing-whitespace + exclude: | + (?x)^( + dicts/| + projects/.*?/dicts/ + ) + - id: check-yaml + - id: end-of-file-fixer + exclude: | + (?x)^( + dicts/| + projects/.*?/dicts/ + ) + - id: requirements-txt-fixer + - id: double-quote-string-fixer + - id: check-merge-conflict + - id: fix-encoding-pragma + args: ["--remove"] + - id: mixed-line-ending + args: ["--fix=lf"] + - id: mixed-line-ending + args: ["--fix=lf"] + - repo: https://gitee.com/openmmlab/mirrors-mdformat + rev: 0.7.9 + hooks: + - id: mdformat + args: ["--number", "--table-width", "200"] + additional_dependencies: + - mdformat-openmmlab + - mdformat_frontmatter + - linkify-it-py + - repo: https://gitee.com/openmmlab/mirrors-docformatter + rev: v1.3.1 + hooks: + - id: docformatter + args: ["--in-place", "--wrap-descriptions", "79"] + # - repo: https://github.com/open-mmlab/pre-commit-hooks + # rev: v0.2.0 # Use the ref you want to point at + # hooks: + # - id: check-algo-readme + # - id: check-copyright + # args: ["mmocr", "tests", "tools"] # these directories will be checked diff --git a/opencompass/openicl/icl_inferencer/icl_clp_inferencer.py b/opencompass/openicl/icl_inferencer/icl_clp_inferencer.py index 21b63264..4c622d26 100644 --- a/opencompass/openicl/icl_inferencer/icl_clp_inferencer.py +++ b/opencompass/openicl/icl_inferencer/icl_clp_inferencer.py @@ -2,7 +2,6 @@ import itertools import os -from functools import partial from typing import List, Optional import torch.nn.functional as F @@ -127,9 +126,6 @@ class CLPInferencer(BaseInferencer): # in case tokenizer returns list for single token choice_ids = list(itertools.chain(*choice_ids)) - get_token_len = partial( - self.model.get_token_len, # COPYBARA_INTERNAL # noqa - eos=False) # COPYBARA_INTERNAL # noqa get_token_len = self.model.get_token_len # prepare in context for each example and control the length diff --git a/opencompass/utils/lark.py b/opencompass/utils/lark.py index 46241f86..ad5e9904 100644 --- a/opencompass/utils/lark.py +++ b/opencompass/utils/lark.py @@ -1,3 +1,4 @@ +import argparse import json from typing import Dict, List, Optional, Union @@ -37,3 +38,21 @@ class LarkReporter: } } requests.post(self.url, data=json.dumps(msg)) + + +def parse_args(): + parser = argparse.ArgumentParser(description='Lark bot reporter') + parser.add_argument('url', help='Lark bot url') + parser.add_argument('content', type=str, help='Content') + parser.add_argument('--title', type=str, help='Title', default=None) + args = parser.parse_args() + return args + + +if __name__ == '__main__': + args = parse_args() + lark = LarkReporter(args.url) + if args.title: + lark.post(args.content, args.title) + else: + lark.post(args.content) diff --git a/requirements.txt b/requirements.txt index 1d882737..970162a9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +absl-py accelerate>=0.19.0 boto3 colossalai @@ -14,6 +15,7 @@ openai pandas<2.0.0 rank_bm25==0.2.2 requests==2.28.1 +rouge_score scikit_learn==1.2.1 sentence_transformers==2.2.2 tabulate