Skip to content

Commit

Permalink
ci: remove yq from e2e.sh
Browse files Browse the repository at this point in the history
Created a utility script called e2e_config_edit.py
to be used in it's place.

Signed-off-by: Ali Maredia <[email protected]>
  • Loading branch information
alimaredia committed Sep 27, 2024
1 parent 66d81c4 commit e71d07b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 13 deletions.
22 changes: 9 additions & 13 deletions scripts/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,8 @@ init_e2e_tests() {
mkdir -p "${dir}"
done

E2E_PATH_DIR="${HOME}/bin"
E2E_LOG_DIR="${HOME}/log"
mkdir -p "${E2E_PATH_DIR}"
mkdir -p "${E2E_LOG_DIR}"
PATH=${E2E_PATH_DIR}:$PATH
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O "${E2E_PATH_DIR}/yq" && chmod +x "${E2E_PATH_DIR}/yq"
}


Expand Down Expand Up @@ -97,19 +93,19 @@ test_init() {
ilab config init --non-interactive --train-profile="${SCRIPTDIR}/test-data/train-profile-a10x8.yaml"

# setting medium size eval specific config
yq e -i '.evaluate.gpus = 8' "${CONFIG_HOME}/instructlab/config.yaml"
PROMETHEUS_8X7B_MODEL_PATH="${CACHE_HOME}/instructlab/models/${PROMETHEUS_8X7B_MODEL}" yq e -i '.evaluate.mt_bench.judge_model = strenv(PROMETHEUS_8X7B_MODEL_PATH)' "${CONFIG_HOME}/instructlab/config.yaml"
python "${SCRIPTDIR}"/e2e_config_edit.py "${CONFIG_HOME}/instructlab/config.yaml" evaluate.gpus 4
python "${SCRIPTDIR}"/e2e_config_edit.py "${CONFIG_HOME}/instructlab/config.yaml" evaluate.mt_bench.judge_model "${CACHE_HOME}/instructlab/models/${PROMETHEUS_8X7B_MODEL}"

# setting medium size SDG specific config
yq e -i '.generate.pipeline = "full"' "${CONFIG_HOME}/instructlab/config.yaml"
MIXTRAL_8X7B_MODEL_PATH="${CACHE_HOME}/instructlab/models/${MIXTRAL_8X7B_MODEL}" yq e -i '.generate.teacher.model_path = strenv(MIXTRAL_8X7B_MODEL_PATH)' "${CONFIG_HOME}/instructlab/config.yaml"
yq e -i '.generate.teacher.vllm.gpus = 8' "${CONFIG_HOME}/instructlab/config.yaml"
yq e -i '.generate.teacher.vllm.llm_family = "mixtral"' "${CONFIG_HOME}/instructlab/config.yaml"
python "${SCRIPTDIR}"/e2e_config_edit.py "${CONFIG_HOME}/instructlab/config.yaml" generate.pipeline full
python "${SCRIPTDIR}"/e2e_config_edit.py "${CONFIG_HOME}/instructlab/config.yaml" generate.teacher.model_path "${CACHE_HOME}/instructlab/models/${MIXTRAL_8X7B_MODEL}"
python "${SCRIPTDIR}"/e2e_config_edit.py "${CONFIG_HOME}/instructlab/config.yaml" generate.teacher.vllm.gpus 4
python "${SCRIPTDIR}"/e2e_config_edit.py "${CONFIG_HOME}/instructlab/config.yaml" generate.teacher.vllm.llm_family mixtral

# setting medium size training specific config
TRAINING_CHECKPOINT_DIR="${DATA_HOME}/instructlab/checkpoints" yq e -i '.train.ckpt_output_dir = strenv(TRAINING_CHECKPOINT_DIR)' "${CONFIG_HOME}/instructlab/config.yaml"
PROMETHEUS_8X7B_MODEL_PATH="${CACHE_HOME}/instructlab/models/${PROMETHEUS_8X7B_MODEL}" yq e -i '.train.phased_mt_bench_judge = strenv(PROMETHEUS_8X7B_MODEL_PATH)' "${CONFIG_HOME}/instructlab/config.yaml"
GRANITE_7B_MODEL_PATH="${CACHE_HOME}/instructlab/models/${GRANITE_7B_MODEL}" yq e -i '.train.model_path = strenv(GRANITE_7B_MODEL_PATH)' "${CONFIG_HOME}/instructlab/config.yaml"
python "${SCRIPTDIR}"/e2e_config_edit.py "${CONFIG_HOME}/instructlab/config.yaml" train.ckpt_output_dir "${CACHE_HOME}/instructlab/checkpoints"
python "${SCRIPTDIR}"/e2e_config_edit.py "${CONFIG_HOME}/instructlab/config.yaml" train.phased_mt_bench_judge "${CACHE_HOME}/instructlab/models/${PROMETHEUS_8X7B_MODEL}"
python "${SCRIPTDIR}"/e2e_config_edit.py "${CONFIG_HOME}/instructlab/config.yaml" train.model_path "${CACHE_HOME}/instructlab/models/${GRANITE_7B_MODEL}"
fi
task ilab Initializing Complete
}
Expand Down
74 changes: 74 additions & 0 deletions scripts/e2e_config_edit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import yaml
import sys

# WARNING:
# This script is a utility meant to be used in scripts/e2e.sh to edit the entries
# in the ilab config from the CLI. It should not be used edit the ilab config by users

def update_yaml(file_path, key, new_value):
try:
with open(file_path, 'r') as file:
try:
data = yaml.safe_load(file)
except yaml.YAMLError as exc:
print(f"Error parsing YAML: {exc}")
sys.exit(1)

keys = key.split(".")
values = []

try:
new_value = int(new_value)
except ValueError:
pass

for key in keys:
if key in data:
values.append(data)
data = data[key]
else:
print(f"Error: Key '{key}' not found in the YAML file.")
sys.exit(1)

if len(keys) != len(values):
print(f"Error: Keys and Values list sizes are not equal")
sys.exit(1)

keys.reverse()
values.reverse()
values[0][keys[0]] = new_value
for i in range(1, len(keys)):
values[i][keys[i]] = values[i-1]
data = values[len(keys)-1]

try:
with open(file_path, 'w') as file:
try:
yaml.safe_dump(data, file)
except yaml.YAMLError as exc:
print(f"Error dumping YAML: {exc}")
sys.exit(1)
except OSError:
print(f"Error: The file '{file_path}' was not found.")
sys.exit(1)

print(f"Updated '{key}' to '{new_value}' in {file_path}")
except OSError:
print(f"Error: The file '{file_path}' was not found.")
sys.exit(1)

if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: python config_editor.py <path to yaml config file> <key(s)> <new value>")
print("Ex: ")
print(" python config_editor.py config.yaml evaluate.gpus 4")
print(" python config_editor.py config.yaml generate.teacher.vllm.model_family mixtral")
sys.exit(1)

print(f"\033[31mWARNING: This script is a utility only meant to be used in scripts/e2e.sh. It should not be used by users to edit the ilab config.yaml\033[0m")

yaml_file = sys.argv[1]
yaml_keys = sys.argv[2]
new_value = sys.argv[3]

update_yaml(yaml_file, yaml_keys, new_value)

0 comments on commit e71d07b

Please sign in to comment.