Skip to content

Commit

Permalink
Merge pull request #18 from SmudgedWings/end
Browse files Browse the repository at this point in the history
'ci_check'
  • Loading branch information
helloyongyang authored Jul 31, 2024
2 parents ddc9048 + da7f862 commit 9c7878a
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: lint

on:
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install pre-commit hook
run: |
pip install pre-commit mmengine
pre-commit install
- name: Linting
run: pre-commit run # --all-files
61 changes: 61 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Check

on:
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8'

- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Download dataset
run: |
# pwd # /home/runner/work/llmc/llmc
cd tools
python download_calib_dataset.py --save_path ../check/datasets/calib --dataset_name pileval
python download_eval_dataset.py --save_path ../check/datasets/eval --dataset_name wikitext2
- name: Download model
run: |
cd ci_check
mkdir -p opt-125m
cp model_urls.txt opt-125m/model_urls.txt
cd opt-125m
wget -i model_urls.txt
wget --no-check-certificate https://hf-mirror.com/facebook/opt-125m/resolve/main/pytorch_model.bin
- name: Run push_tests
run: |
cd ci_check # /home/runner/work/llmc/llmc/ci_check
python change_files.py
bash run.sh
- name: Check success
if: ${{ success() }}
run: echo "All steps completed successfully. Success!"

- name: Clean up
if: ${{ always() }}
run: |
cd ..
rm -rf opt-125m
rm -rf check
60 changes: 60 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
exclude: |
(?x)^(
imgs/|
docs/|
ci_check/|
requirements/|
scripts/
)
repos:
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
exclude: configs/
- repo: https://github.com/PyCQA/isort
rev: 5.11.5
hooks:
- id: isort
exclude: configs/
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.32.0
hooks:
- id: yapf
exclude: configs/
- repo: https://github.com/codespell-project/codespell
rev: v2.2.1
hooks:
- id: codespell
exclude: |
(?x)^(
.*\.jsonl|
.*\.md.template|
configs/
)
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-yaml
- 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"]
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.9
hooks:
- id: mdformat
args: ["--number", "--table-width", "200"]
additional_dependencies:
- mdformat-openmmlab
- mdformat_frontmatter
- linkify-it-py
exclude: configs/
- repo: https://github.com/myint/docformatter
rev: v1.3.1
hooks:
- id: docformatter
args: ["--in-place", "--wrap-descriptions", "88"]
32 changes: 32 additions & 0 deletions ci_check/awq_w4a16_fakequant_eval.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
base:
seed: &seed 42
model:
type: Opt
path: /home/runner/work/llmc/llmc/ci_check/opt-125m
torch_dtype: auto
calib:
name: pileval
download: False
path: /home/runner/work/llmc/llmc/check/datasets/calib/pileval
n_samples: 4 # 128
bs: -1
seq_len: 16 # 512
preproc: pileval_awq
seed: *seed
eval:
eval_pos: [pretrain, transformed, fake_quant]
name: wikitext2
download: False
path: /home/runner/work/llmc/llmc/check/datasets/eval/wikitext2
bs: 1
seq_len: 16 # 2048
quant:
method: Awq
weight:
bit: 4
symmetric: False
granularity: per_group
group_size: 128
save:
save_trans: False
save_path: /home/runner/work/llmc/llmc/save/opt-125m_awq_w4a16
97 changes: 97 additions & 0 deletions ci_check/change_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import os

# 文件路径
cpu_txt_path = 'cpu.txt'

def modify_file(filepath, modifications):
with open(filepath, 'r') as file:
lines = file.readlines()

# 应用修改
new_lines = []
for line in lines:
# 替换操作
for search, replace in modifications['modifications']:
if search in line:
line = line.replace(search, replace)
new_lines.append(line)

# 在文件开头插入新内容
with open(filepath, 'w') as file:
file.writelines(modifications['header'] + new_lines)

def main():
with open(cpu_txt_path, 'r') as file:
file_paths = file.readlines()

for file_path in file_paths:
file_path = file_path.strip()
if not file_path:
continue

if file_path == '../llmc/__main__.py':
modifications = {
'header': [
'device_zbl = "cpu"\n',
'use_cuda = (device_zbl != "cpu")\n'
],
'modifications': [
('torch.cuda.empty_cache()', 'if use_cuda: torch.cuda.empty_cache()')
]
}
elif file_path == '../llmc/compression/quantization/awq.py':
modifications = {
'header': [
'n_grid_zbl = 1\n'
],
'modifications': [
('n_grid = 20', 'n_grid = n_grid_zbl')
]
}
elif file_path == '../llmc/compression/quantization/base_blockwise_quantization.py':
modifications = {
'header': [
'device_zbl = "cpu"\n',
'use_cuda = (device_zbl != "cpu")\n'
],
'modifications': [
('.cuda()', '.to(device_zbl)'),
('torch.cuda.empty_cache()', 'if use_cuda: torch.cuda.empty_cache()')
]
}
elif file_path == '../llmc/models/base_model.py':
modifications = {
'header': [
'device_zbl = "cpu"\n',
'use_cuda = (device_zbl != "cpu")\n'
],
'modifications': [
('.cuda()', '.to(device_zbl)'),
('self.move_embed_to_device("cuda")', 'self.move_embed_to_device(device_zbl)')
]
}
elif file_path == '../llmc/eval/eval_ppl.py':
modifications = {
'header': [
'device_zbl = "cpu"\n',
'use_cuda = (device_zbl != "cpu")\n',
'nsamples_zbl = 1\n'
],
'modifications': [
('.cuda()', '.to(device_zbl)'),
('torch.cuda.empty_cache()', 'if use_cuda: torch.cuda.empty_cache()'),
('nlls = []', 'nlls = []; nsamples = nsamples_zbl')
]
}
else:
print(f"File {file_path} not recognized or not specified for modification.")
continue

# 修改文件
if os.path.exists(file_path):
modify_file(file_path, modifications)
else:
print(f"File {file_path} does not exist.")

if __name__ == "__main__":
main()
5 changes: 5 additions & 0 deletions ci_check/cpu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
../llmc/compression/quantization/base_blockwise_quantization.py
../llmc/__main__.py
../llmc/eval/eval_ppl.py
../llmc/compression/quantization/awq.py
../llmc/models/base_model.py
6 changes: 6 additions & 0 deletions ci_check/model_urls.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
https://hf-mirror.com/facebook/opt-125m/resolve/main/config.json
https://hf-mirror.com/facebook/opt-125m/resolve/main/generation_config.json
https://hf-mirror.com/facebook/opt-125m/resolve/main/merges.txt
https://hf-mirror.com/facebook/opt-125m/resolve/main/special_tokens_map.json
https://hf-mirror.com/facebook/opt-125m/resolve/main/tokenizer_config.json
https://hf-mirror.com/facebook/opt-125m/resolve/main/vocab.json
10 changes: 10 additions & 0 deletions ci_check/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

current_directory=$(pwd)
llmc=$(echo "$current_directory" | sed 's/\/ci_check$//')
export PYTHONPATH=$llmc:$PYTHONPATH


cd ../scripts

python -m llmc --config ../ci_check/awq_w4a16_fakequant_eval.yml

0 comments on commit 9c7878a

Please sign in to comment.