Skip to content

Commit

Permalink
support windows (#356)
Browse files Browse the repository at this point in the history
Co-authored-by: wenduren <[email protected]>
Co-authored-by: lwj-st <[email protected]>
Co-authored-by: wangzhihong <[email protected]>
  • Loading branch information
4 people authored Nov 22, 2024
1 parent d2c5300 commit 0358d6c
Show file tree
Hide file tree
Showing 28 changed files with 337 additions and 93 deletions.
186 changes: 186 additions & 0 deletions .github/workflows/win_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
name: Test on Windows

on:
push:
branches:
- main
pull_request_target:
branches:
- main
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.id || github.ref }}
cancel-in-progress: true

env:
POETRY_VERSION: "1.8.3"
PYTHON_VERSION: "3.10.9"

jobs:
win-basic_tests:
runs-on: windows-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Fetch PR source branch
if: github.event_name == 'pull_request_target'
run: |
if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
echo ${{ github.event.pull_request.head.repo.clone_url }}
echo ${{ github.event.pull_request.head.ref }}
git remote add external_repo ${{ github.event.pull_request.head.repo.clone_url }}
git fetch external_repo ${{ github.event.pull_request.head.ref }}:pr_branch
else
echo ${{ github.event.pull_request.head.ref }}
git fetch origin ${{ github.event.pull_request.head.ref }}:pr_branch
fi
- name: Merge PR branch into main
if: github.event_name == 'pull_request_target'
run: |
git checkout main
git merge --no-ff pr_branch
git submodule update --init
- name: Copy poetry.lock to root directory
shell: bash
run: |
git branch
cd LazyLLM-Env && git branch
cd ..
cp LazyLLM-Env/poetry.lock .
ls
- name: Set up python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Download model
shell: bash
run: |
pip install modelscope pyyaml
mkdir C:/Users/runneradmin/.lazyllm
ls C:/Users/runneradmin/.lazyllm
mkdir -p C:/Users/runneradmin/.cache/modelscope/hub
ln -s C:/Users/runneradmin/.cache/modelscope/hub C:/Users/runneradmin/.lazyllm/model
modelscope download Shanghai_AI_Laboratory/internlm2-chat-7b &
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}

- name: Build project with Poetry
shell: bash
run: |
poetry build
- name: List dist directory
shell: bash
run: ls dist

- name: Install the built package
shell: bash
run: |
pip install dist/lazyllm*.whl
- name: basic_tests
shell: bash
run: |
git clone https://[email protected]/LazyAGI/LazyLLM-Data.git D:/a/LazyLLM/data
pip install -r tests/requirements.txt
export LAZYLLM_DATA_PATH=D:/a/LazyLLM/data
python -m pytest -m "not skip_on_win" -v --reruns=2 tests/basic_tests
timeout-minutes: 30
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }}


win-charge_tests:
if: |
!contains(github.event.head_commit.message, '[skip ci]')
&& !contains(github.event.pull_request.title, '[skip ci]')
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Merge PR branch into main
if: github.event_name == 'pull_request_target'
run: |
if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
echo ${{ github.event.pull_request.head.repo.clone_url }}
echo ${{ github.event.pull_request.head.ref }}
git remote add external_repo ${{ github.event.pull_request.head.repo.clone_url }}
git fetch external_repo ${{ github.event.pull_request.head.ref }}:pr_branch
else
echo ${{ github.event.pull_request.head.ref }}
git fetch origin ${{ github.event.pull_request.head.ref }}:pr_branch
fi
- name: Merge PR branch into main
if: github.event_name == 'pull_request_target'
shell: bash
run: |
git checkout main
git merge --no-ff pr_branch
git submodule update --init
- name: Copy poetry.lock to root directory
shell: bash
run: |
git branch
cd LazyLLM-Env && git branch
cd ..
cp LazyLLM-Env/poetry.lock .
- name: Set up python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}

- name: Build project with Poetry
shell: bash
run: |
poetry build
- name: List dist directory
shell: bash
run: ls dist

- name: Install the built package
shell: bash
run: |
pip install dist/lazyllm*.whl
- name: charge_tests
shell: bash
run : |
git clone https://[email protected]/LazyAGI/LazyLLM-Data.git D:/a/LazyLLM/data
pip install -r tests/requirements.txt
export LAZYLLM_DATA_PATH=D:/a/LazyLLM/data
python -m pytest -v --reruns=2 tests/charge_tests
env :
LAZYLLM_KIMI_API_KEY: ${{ secrets.LAZYLLM_KIMI_API_KEY }}
LAZYLLM_GLM_API_KEY: ${{ secrets.LAZYLLM_GLM_API_KEY }}
LAZYLLM_QWEN_API_KEY: ${{ secrets.LAZYLLM_QWEN_API_KEY }}
LAZYLLM_SENSENOVA_API_KEY: ${{ secrets.LAZYLLM_SENSENOVA_API_KEY }}
LAZYLLM_SENSENOVA_SECRET_KEY: ${{ secrets.LAZYLLM_SENSENOVA_SECRET_KEY }}
LAZYLLM_PostgreSQL_URL: ${{ secrets.LAZYLLM_PostgreSQL_URL }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
timeout-minutes: 30
7 changes: 3 additions & 4 deletions examples/rag_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# flake8: noqa: F821

import lazyllm
from lazyllm import pipeline, parallel, bind, SentenceSplitter, Document, Retriever, Reranker
from lazyllm import pipeline, parallel, bind, OnlineEmbeddingModule, SentenceSplitter, Document, Retriever, Reranker

# Before running, set the environment variable:
#
Expand All @@ -27,15 +27,14 @@

prompt = 'You will play the role of an AI Q&A assistant and complete a dialogue task. In this task, you need to provide your answer based on the given context and question.'

documents = Document(dataset_path="rag_master", embed=lazyllm.OnlineEmbeddingModule(), manager=False)
documents = Document(dataset_path="rag_master", embed=OnlineEmbeddingModule(), manager=False)
documents.create_node_group(name="sentences", transform=SentenceSplitter, chunk_size=1024, chunk_overlap=100)

with pipeline() as ppl:
with parallel().sum as ppl.prl:
prl.retriever1 = Retriever(documents, group_name="sentences", similarity="cosine", topk=3)
prl.retriever2 = Retriever(documents, "CoarseChunk", "bm25_chinese", 0.003, topk=3)

ppl.reranker = Reranker("ModuleReranker", model="bge-reranker-large", topk=1, output_format='content', join=True) | bind(query=ppl.input)
ppl.reranker = Reranker("ModuleReranker", model=OnlineEmbeddingModule(type="rerank"), topk=1, output_format='content', join=True) | bind(query=ppl.input)
ppl.formatter = (lambda nodes, query: dict(context_str=nodes, query=query)) | bind(query=ppl.input)
ppl.llm = lazyllm.OnlineChatModule(stream=False).prompt(lazyllm.ChatPrompter(prompt, extro_keys=["context_str"]))

Expand Down
2 changes: 1 addition & 1 deletion lazyllm/common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"<level>{level}</level>: ({name}:{line}) <cyan>{message}</cyan>",
"LOG_FORMAT",
)
lazyllm.config.add("log_dir", str, "~/.lazyllm", "LOG_DIR")
lazyllm.config.add("log_dir", str, os.path.join(os.path.expanduser('~'), '.lazyllm'), "LOG_DIR")
lazyllm.config.add("log_file_level", str, "ERROR", "LOG_FILE_LEVEL")
lazyllm.config.add("log_file_size", str, "4 MB", "LOG_FILE_SIZE")
lazyllm.config.add("log_file_retention", str, "7 days", "LOG_FILE_RETENTION")
Expand Down
4 changes: 2 additions & 2 deletions lazyllm/components/auto/configure/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ def query_deploy(self, gpu_type: str, gpu_num: int, model_name: str, max_token_n
def get_configer():
global configer
if configer is None:
configer = AutoConfig(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'configs/finetune.csv'),
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'configs/deploy.csv'))
configer = AutoConfig(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'configs', 'finetune.csv'),
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'configs', 'deploy.csv'))
return configer
2 changes: 1 addition & 1 deletion lazyllm/components/finetune/alpaca-lora/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def train( # noqa C901
# model/data params
base_model: str = "", # the only required argument
data_path: str = "",
output_dir: str = "./output_dir",
output_dir: str = os.path.abspath("./output_dir"),
# training hyperparams
batch_size: int = 128,
micro_batch_size: int = 4,
Expand Down
13 changes: 7 additions & 6 deletions lazyllm/components/finetune/alpacalora.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ def __init__(self,
if not merge_path:
save_path = os.path.join(lazyllm.config['train_target_root'], target_path)
target_path, merge_path = os.path.join(save_path, "lazyllm_lora"), os.path.join(save_path, "lazyllm_merge")
os.system(f'mkdir -p {target_path} {merge_path}')
os.makedirs(target_path, exist_ok=True)
os.makedirs(merge_path, exist_ok=True)
super().__init__(
base_model,
target_path,
launcher=launcher,
)
self.folder_path = os.path.dirname(os.path.abspath(__file__))
deepspeed_config_path = os.path.join(self.folder_path, 'alpaca-lora/ds.json')
deepspeed_config_path = os.path.join(self.folder_path, 'alpaca-lora', 'ds.json')
self.kw = copy.deepcopy(self.defatult_kw)
self.kw['deepspeed'] = deepspeed_config_path
self.kw['nccl_port'] = random.randint(19000, 20500)
Expand All @@ -67,23 +68,23 @@ def cmd(self, trainset, valset=None) -> str:
if not self.kw['data_path']:
self.kw['data_path'] = trainset

run_file_path = os.path.join(self.folder_path, 'alpaca-lora/finetune.py')
run_file_path = os.path.join(self.folder_path, 'alpaca-lora', 'finetune.py')
cmd = (f'python {run_file_path} '
f'--base_model={self.base_model} '
f'--output_dir={self.target_path} '
)
cmd += self.kw.parse_kwargs()
cmd += f' 2>&1 | tee {self.target_path}/{self.model_name}_$(date +"%Y-%m-%d_%H-%M-%S").log'
cmd += f' 2>&1 | tee {os.path.join(self.target_path, self.model_name)}_$(date +"%Y-%m-%d_%H-%M-%S").log'

if self.merge_path:
run_file_path = os.path.join(self.folder_path, 'alpaca-lora/utils/merge_weights.py')
run_file_path = os.path.join(self.folder_path, 'alpaca-lora', 'utils', 'merge_weights.py')

cmd = [cmd,
f'python {run_file_path} '
f'--base={self.base_model} '
f'--adapter={self.target_path} '
f'--save_path={self.merge_path} ',
f' cp {self.base_model}/{self.cp_files} {self.merge_path} '
f' cp {os.path.join(self.base_model, self.cp_files)} {self.merge_path} '
]

# cmd = 'realpath .'
Expand Down
11 changes: 6 additions & 5 deletions lazyllm/components/finetune/collie.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def __init__(self,
if not merge_path:
save_path = os.path.join(lazyllm.config['train_target_root'], target_path)
target_path, merge_path = os.path.join(save_path, "lazyllm_lora"), os.path.join(save_path, "lazyllm_merge")
os.system(f'mkdir -p {target_path} {merge_path}')
os.makedirs(target_path, exist_ok=True)
os.makedirs(merge_path, exist_ok=True)
super().__init__(
base_model,
target_path,
Expand All @@ -63,23 +64,23 @@ def cmd(self, trainset, valset=None) -> str:
if not self.kw['data_path']:
self.kw['data_path'] = trainset

run_file_path = os.path.join(self.folder_path, 'collie/finetune.py')
run_file_path = os.path.join(self.folder_path, 'collie', 'finetune.py')
cmd = (f'python {run_file_path} '
f'--base_model={self.base_model} '
f'--output_dir={self.target_path} '
)
cmd += self.kw.parse_kwargs()
cmd += f' 2>&1 | tee {self.target_path}/{self.model_name}_$(date +"%Y-%m-%d_%H-%M-%S").log'
cmd += f' 2>&1 | tee {os.path.join(self.target_path, self.model_name)}_$(date +"%Y-%m-%d_%H-%M-%S").log'

if self.merge_path:
run_file_path = os.path.join(self.folder_path, 'alpaca-lora/utils/merge_weights.py')
run_file_path = os.path.join(self.folder_path, 'alpaca-lora', 'utils', 'merge_weights.py')

cmd = [cmd,
f'python {run_file_path} '
f'--base={self.base_model} '
f'--adapter={self.target_path} '
f'--save_path={self.merge_path} ',
f' cp {self.base_model}/{self.cp_files} {self.merge_path} '
f' cp {os.path.join(self.base_model,self.cp_files)} {self.merge_path} '
]

return cmd
4 changes: 2 additions & 2 deletions lazyllm/components/finetune/llamafactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self,
self.export_config_path = export_config_path
self.config_folder_path = os.path.dirname(os.path.abspath(__file__))

default_config_path = os.path.join(self.config_folder_path, 'llamafactory/sft.yaml')
default_config_path = os.path.join(self.config_folder_path, 'llamafactory', 'sft.yaml')
self.template_dict = ArgsDict(self.load_yaml(default_config_path))

if self.config_path:
Expand All @@ -64,7 +64,7 @@ def __init__(self,
self.template_dict['template'] = self.get_template_name(base_model)
self.template_dict.check_and_update(kw)

default_export_config_path = os.path.join(self.config_folder_path, 'llamafactory/lora_export.yaml')
default_export_config_path = os.path.join(self.config_folder_path, 'llamafactory', 'lora_export.yaml')
self.export_dict = ArgsDict(self.load_yaml(default_export_config_path))

if self.export_config_path:
Expand Down
4 changes: 2 additions & 2 deletions lazyllm/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class Mode(Enum):


class Config(object):
def __init__(self, prefix='LAZYLLM', home='~/.lazyllm/'):
def __init__(self, prefix='LAZYLLM', home=os.path.join(os.path.expanduser('~'), '.lazyllm')):
self._config_params = dict()
self._env_map_name = dict()
self.prefix = prefix
self.impl, self.cfgs = dict(), dict()
self.add('home', str, os.path.expanduser(home), 'HOME')
os.system(f'mkdir -p {home}')
os.makedirs(home, exist_ok=True)
self.cgf_path = os.path.join(self['home'], 'config.json')
if os.path.exists(self.cgf_path):
with open(self.cgf_path, 'r+') as f:
Expand Down
6 changes: 3 additions & 3 deletions lazyllm/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def _start(self, *, fixed):
cmd = self.get_executable_cmd(fixed=fixed)
LOG.info(f'Command: {cmd}')
if lazyllm.config['mode'] == lazyllm.Mode.Display: return
self.ps = subprocess.Popen(cmd.cmd, shell=True, executable='/bin/bash',
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
self.ps = subprocess.Popen(cmd.cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
self._get_jobid()
self._enqueue_subprocess_output(hooks=self.output_hooks)

Expand Down Expand Up @@ -234,7 +234,7 @@ def _get_jobid(self):
self.jobid = self.ps.pid if self.ps else None

def get_jobip(self):
return '0.0.0.0'
return '127.0.0.1'

def wait(self):
if self.ps:
Expand Down
2 changes: 1 addition & 1 deletion lazyllm/module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def _get_train_tasks_impl(self, mode: Optional[str] = None, **kw):
self._trainset, str) else self._trainset
target_path = self._generate_target_path()
if not os.path.exists(target_path):
os.system(f'mkdir -p {target_path}')
os.makedirs(target_path, exist_ok=True)

kw = kw or self._get_train_or_deploy_args(mode, disable=['base_model', 'target_path'])
task = getattr(self, f'_{mode}')(base_model=self._base_model, target_path=target_path, **kw)
Expand Down
Loading

0 comments on commit 0358d6c

Please sign in to comment.