Skip to content

Commit

Permalink
add llm-on-ray finetune
Browse files Browse the repository at this point in the history
Signed-off-by: Wu, Xiaochang <[email protected]>
  • Loading branch information
xwu99 committed Jun 24, 2024
1 parent e9cb8c5 commit 6608998
Show file tree
Hide file tree
Showing 4 changed files with 690 additions and 0 deletions.
38 changes: 38 additions & 0 deletions comps/finetuning/llm_on_ray/common/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Copyright 2023 The LLM-on-Ray Authors.
#
# 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.
#

import os
import glob
import importlib

from llm_on_ray.common.logging import logger


def import_all_modules(basedir, prefix=None):
all_py_files = glob.glob(basedir + "/*.py")
modules = [os.path.basename(f) for f in all_py_files]

for module in modules:
if not module.startswith("_"):
module = module.rstrip(".py")
if prefix is None:
module_name = module
else:
module_name = f"{prefix}.{module}"
try:
importlib.import_module(module_name)
except Exception:
logger.warning(f"import {module_name} error", exc_info=True)
67 changes: 67 additions & 0 deletions comps/finetuning/llm_on_ray/common/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#
# Copyright 2023 The LLM-on-Ray Authors.
#
# 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.
#

import logging
import logging.config
import traceback
import functools

__all__ = ["logger", "get_logger"]

use_accelerate_log = False
logger_name = "common"

logging_config = {
"version": 1,
"loggers": {
"root": {"level": "INFO", "handlers": ["consoleHandler"]},
"common": {
"level": "INFO",
"handlers": ["consoleHandler"],
"qualname": "common",
"propagate": 0,
},
},
"handlers": {
"consoleHandler": {
"class": "logging.StreamHandler",
"level": "INFO",
"formatter": "standardFormatter",
},
},
"formatters": {
"standardFormatter": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
"datefmt": "",
}
},
}

if logging_config is not None:
try:
logging.config.dictConfig(logging_config)
except Exception:
traceback.print_exc()
exit(1)

if use_accelerate_log:
import accelerate

get_logger = functools.partial(accelerate.logging.get_logger, name=logger_name)
else:
get_logger = functools.partial(logging.getLogger, name=logger_name)

logger = get_logger()
Loading

0 comments on commit 6608998

Please sign in to comment.