-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: polish starter project code style (#8)
* feat: polish project template code style * fix: pre-commit * stage: step by step * stage: description
- Loading branch information
Showing
11 changed files
with
108 additions
and
51 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
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 was deleted.
Oops, something went wrong.
15 changes: 10 additions & 5 deletions
15
colossalai_platform/cli/commands/projects/HyperParameters.json
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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
{ | ||
"HyperParameters": [ | ||
{ | ||
"name": "epoch", | ||
"types": "string", | ||
"defaultValue": "10" | ||
} | ||
// TODO: Add your parameters like this: | ||
// { | ||
// "name": "epoch", | ||
// "types": "string", | ||
// "defaultValue": "10", | ||
// "description": "Number of epochs for training" | ||
// } | ||
// | ||
// At our platform, it would be injected into `train.sh` | ||
// as environment variable ${epoch} | ||
] | ||
} |
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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
# Code generated by ColossalAI-Platform-CLI. DO NOT EDIT. | ||
def patch_tensorboard(): | ||
def _patch_tensorboard(): | ||
try: | ||
from tensorboard.compat.tensorflow_stub.io.gfile import LocalFileSystem | ||
# hack to make tensorboard compatible with Cloud File System | ||
delattr(LocalFileSystem, "append") | ||
except ImportError: | ||
print("Tensorboard patch failed. Please check your tensorboard version.") | ||
|
||
|
||
def patch_platform_specific_dependencies(): | ||
_patch_tensorboard() |
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 |
---|---|---|
@@ -1,38 +1,68 @@ | ||
import os | ||
from patch import patch_tensorboard | ||
import argparse | ||
import types | ||
from patch import patch_platform_specific_dependencies | ||
|
||
# ================================== | ||
# Code generated by ColossalAI-Platform-CLI. DO NOT EDIT. | ||
# Please do not remove this call, | ||
# the platform's runtime environment needs it. | ||
patch_platform_specific_dependencies() | ||
|
||
# =================================================================== | ||
# Example code generated by ColossalAI-Platform-CLI. | ||
# | ||
# ColossalAI Platform Specification | ||
# Start | ||
# ================================== | ||
# Modify it to fit your needs. | ||
# =================================================================== | ||
|
||
# patch dependencies | ||
patch_tensorboard() | ||
|
||
# Environment variables for your data access | ||
PROJECT_DIR = os.environ['PROJECT_DIR'] | ||
DATASET_DIR = os.environ['DATASET_DIR'] | ||
OUTPUT_DIR = os.environ['OUTPUT_DIR'] | ||
INPUT_MODEL_DIR = os.environ['MODEL_DIR'] | ||
CHECKPOINT_DIR = os.path.join(OUTPUT_DIR, 'checkpoint') | ||
TENSORBOARD_DIR = os.path.join(OUTPUT_DIR, 'tensorboard') | ||
def add_platform_args(parser: argparse.ArgumentParser): | ||
# required arguments | ||
parser.add_argument( | ||
"--project_dir", | ||
type=str, | ||
required=True, | ||
help="The directory contains the project code.", | ||
) | ||
parser.add_argument( | ||
"--dataset_dir", | ||
type=str, | ||
required=True, | ||
help="The directory contains the training dataset.", | ||
) | ||
parser.add_argument( | ||
"--output_dir", | ||
type=str, | ||
required=True, | ||
help="The directory project would write output into.", | ||
) | ||
|
||
# optional arguments, add more if you need | ||
parser.add_argument( | ||
"--model_dir", | ||
type=str, | ||
default=None, | ||
help="The directory contains the model to finetune.", | ||
) | ||
|
||
# create directories | ||
def create_if_not_exist(path): | ||
# create if not exists | ||
if not os.path.exists(path): | ||
os.makedirs(path, exist_ok=True) | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="training script") | ||
add_platform_args(parser) | ||
args = parser.parse_args() | ||
|
||
create_if_not_exist(CHECKPOINT_DIR) | ||
create_if_not_exist(TENSORBOARD_DIR) | ||
# There are some path conventions: | ||
# | ||
# $OUTPUT_DIR/tensorboard: | ||
# The platform-builtin tensorboard expects events to be here. | ||
# $OUTPUT_DIR/checkpoint | ||
# The platform-builtin checkpoint recovery feature | ||
# expects the checkpoint to be here. | ||
tensorboard_dir = os.path.join(args.output_dir, "tensorboard") | ||
os.mkdir(tensorboard_dir, exist_ok=True) | ||
checkpoint_dir = os.path.join(args.output_dir, "checkpoint") | ||
os.mkdir(checkpoint_dir, exist_ok=True) | ||
|
||
# ================================== | ||
# Code generated by ColossalAI-Platform-CLI. DO NOT EDIT. | ||
# | ||
# ColossalAI Platform Specification | ||
# End | ||
# ================================== | ||
# TODO: your training code here | ||
|
||
|
||
if __name__ == "__main__": | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
#!/usr/bin/env bash | ||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
|
||
# =================================================================== | ||
# Welcome to ColossalAI Platform! | ||
# =================================================================== | ||
# Those environment variables would be injected by the runner: | ||
# | ||
# 1. ColossalAI Platform defined ones: | ||
# PROJECT_DIR, DATASET_DIR, MODEL_DIR, OUTPUT_DIR, SCRIPT_DIR | ||
# | ||
# 2. Required by torchrun: | ||
# NNODES, NPROC_PER_NODE, NODE_RANK, MASTER_ADDR, MASTER_PORT | ||
# | ||
# 3. Hyperparameters from configuration UI: | ||
# (check HyperParameters.json for more details) | ||
# | ||
# After that, the runner would execute `train.sh`, this script. | ||
# =================================================================== | ||
|
||
torchrun --nnodes ${NNODES} \ | ||
--nproc_per_node ${NPROC_PER_NODE} \ | ||
--node_rank ${NODE_RANK} \ | ||
--master_addr ${MASTER_ADDR} \ | ||
--master_port ${MASTER_PORT} \ | ||
${SCRIPT_DIR}/train.py \ | ||
--epoch ${epoch} # add your argument passing here | ||
--project_dir ${PROJECT_DIR} \ | ||
--dataset_dir ${DATASET_DIR} \ | ||
--model_dir ${MODEL_DIR} \ | ||
--output_dir ${OUTPUT_DIR} | ||
|
||
# TODO: add more argument passing here |
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 |
---|---|---|
@@ -1 +1 @@ | ||
click | ||
click |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.1 | ||
0.0.1 |