forked from PaddlePaddle/PaddleNLP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Pre-Training] ERNIE-CW pre-training tasks docs. (PaddlePaddle#3111)
* add ernie-large config * update * update clue finetune. * unused delete. * update * support no nsp for enrie. * fix evaluation * fix amp o2 save_dtype bugs. * extand ernie. * fix ernie pretrain with ## vocab. * extend vocab * support custom tokenizer. * add some comments. * fix bugs. * add comments. * fix bug. * fix run_pretrain_static logging. * fix all gather. * fix a100 * fix * fix bugs * fix save * tmp commit for pre-process. * Update README.md * Update README.md * add amp o1 support * ernie cw readme. * fix * throw error when dataset is invalid. * update document. * refine readme. * fix * refactor * refator2 * Add pre-training introduction. * update image width. * refine doc * fit table width. * fix c++ style * fix table * refine docs * refine model_zoo/ernie-1.0/README.md * readfine readme. * fix link * fix bug * fix documents. * add weight. * fix config
- Loading branch information
Showing
28 changed files
with
2,230 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import argparse | ||
import io | ||
import re | ||
import sys | ||
import os | ||
import datetime | ||
|
||
COPYRIGHT = '''Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License.''' | ||
|
||
def _generate_copyright(comment_mark): | ||
copyright=COPYRIGHT.split(os.linesep) | ||
header = copyright[0].rstrip() | ||
|
||
p = re.search('(\d{4})', header).group(0) | ||
now = datetime.datetime.now() | ||
|
||
header = header.replace(p,str(now.year)) | ||
|
||
ans=[comment_mark + " " + header + os.linesep] | ||
for idx, line in enumerate(copyright[1:]): | ||
ans.append(comment_mark + " " + line.rstrip() + os.linesep) | ||
|
||
return ans | ||
|
||
def _get_comment_mark(path): | ||
lang_type=re.compile(r"\.(py|sh)$") | ||
if lang_type.search(path) is not None: | ||
return "#" | ||
|
||
lang_type=re.compile(r"\.(h|c|hpp|cc|cpp|cu|go|cuh|proto)$") | ||
if lang_type.search(path) is not None: | ||
return "//" | ||
|
||
return None | ||
|
||
|
||
RE_ENCODE = re.compile(r"^[ \t\v]*#.*?coding[:=]", re.IGNORECASE) | ||
RE_COPYRIGHT = re.compile(r".*Copyright \(c\) \d{4}", re.IGNORECASE) | ||
RE_SHEBANG = re.compile(r"^[ \t\v]*#[ \t]?\!") | ||
|
||
def _check_copyright(path): | ||
head=[] | ||
try: | ||
with open(path) as f: | ||
head = [next(f) for x in range(4)] | ||
except StopIteration: | ||
pass | ||
|
||
for idx, line in enumerate(head): | ||
if RE_COPYRIGHT.search(line) is not None: | ||
return True | ||
|
||
return False | ||
|
||
def generate_copyright(path, comment_mark): | ||
original_contents = io.open(path, encoding="utf-8").readlines() | ||
head = original_contents[0:4] | ||
|
||
insert_line_no=0 | ||
for i, line in enumerate(head): | ||
if RE_ENCODE.search(line) or RE_SHEBANG.search(line): | ||
insert_line_no=i+1 | ||
|
||
copyright = _generate_copyright(comment_mark) | ||
if insert_line_no == 0: | ||
new_contents = copyright | ||
if len(original_contents) > 0 and len(original_contents[0].strip()) != 0: | ||
new_contents.append(os.linesep) | ||
new_contents.extend(original_contents) | ||
else: | ||
new_contents=original_contents[0:insert_line_no] | ||
new_contents.append(os.linesep) | ||
new_contents.extend(copyright) | ||
if len(original_contents) > insert_line_no and len(original_contents[insert_line_no].strip()) != 0: | ||
new_contents.append(os.linesep) | ||
new_contents.extend(original_contents[insert_line_no:]) | ||
new_contents="".join(new_contents) | ||
|
||
with io.open(path, 'w') as output_file: | ||
output_file.write(new_contents) | ||
|
||
|
||
|
||
def main(argv=None): | ||
parser = argparse.ArgumentParser( | ||
description='Checker for copyright declaration.') | ||
parser.add_argument('filenames', nargs='*', help='Filenames to check') | ||
args = parser.parse_args(argv) | ||
|
||
retv = 0 | ||
for path in args.filenames: | ||
comment_mark = _get_comment_mark(path) | ||
if comment_mark is None: | ||
print("warning:Unsupported file", path, file=sys.stderr) | ||
continue | ||
|
||
if _check_copyright(path): | ||
continue | ||
|
||
generate_copyright(path, comment_mark) | ||
|
||
|
||
if __name__ == '__main__': | ||
exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.