-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pipeline Updates for RHEL AI 1.3 #230
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d4e91ee
update rhelai 1.2 to 1.3
MichaelClifford ba97769
wip: working on changes needed for RHELAI1.3
MichaelClifford b235539
fix: set_precomputed_skills_data_ratio if EACCES
leseb 262fb94
set copytree dirs_exist_ok to True in sdg op
MichaelClifford 46b9149
fix: set a default to sdg_sample_size
leseb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -39,21 +39,9 @@ def sdg_op( | |
): | ||
from os import getenv, path | ||
|
||
import instructlab.sdg | ||
import openai | ||
import yaml | ||
from instructlab.sdg import generate_data | ||
from instructlab.sdg.utils.taxonomy import read_taxonomy | ||
|
||
def set_precomputed_skills_data_ratio(sampling_size: float): | ||
skills_recipe = "/usr/share/instructlab/sdg/default_data_recipes/skills.yaml" | ||
if path.exists(skills_recipe): | ||
with open(skills_recipe, "r") as file: | ||
skills_yaml = yaml.load(file, Loader=yaml.Loader) | ||
|
||
skills_yaml["datasets"][0]["sampling_size"] = sampling_size | ||
|
||
with open(skills_recipe, "w", encoding="utf-8") as file: | ||
yaml.dump(skills_yaml, file) | ||
|
||
api_key = getenv("api_key") | ||
model = getenv("model") | ||
|
@@ -73,25 +61,120 @@ def set_precomputed_skills_data_ratio(sampling_size: float): | |
|
||
print("Generating synthetic dataset for:") | ||
print() | ||
print(read_taxonomy(taxonomy_path, taxonomy_base)) | ||
|
||
set_precomputed_skills_data_ratio(sampling_size=sdg_sampling_size) | ||
|
||
# generate_data has a magic word for its taxonomy_base argument - 'empty' | ||
# it allows generating from the whole repo, see: | ||
# https://github.com/instructlab/sdg/blob/c6a9e74a1618b1077cd38e713b8aaed8b7c0c8ce/src/instructlab/sdg/utils/taxonomy.py#L230 | ||
generate_data( | ||
client=client, | ||
num_instructions_to_generate=num_instructions_to_generate, | ||
output_dir=sdg_path, | ||
taxonomy=taxonomy_path, | ||
taxonomy_base=taxonomy_base, | ||
model_name=model, | ||
pipeline=pipeline, | ||
chunk_word_count=1000, | ||
server_ctx_size=4096, | ||
print( | ||
instructlab.sdg.utils.taxonomy.read_taxonomy( | ||
taxonomy_path, taxonomy_base, document_output_dir=f"{sdg_path}/documents" | ||
) | ||
) | ||
|
||
# Generate synthetic dataset | ||
# 1.0 is the default size | ||
if sdg_sampling_size == 1.0: | ||
# generate_data has a magic word for its taxonomy_base argument - 'empty' | ||
# it allows generating from the whole repo, see: | ||
# https://github.com/instructlab/sdg/blob/c6a9e74a1618b1077cd38e713b8aaed8b7c0c8ce/src/instructlab/sdg/utils/taxonomy.py#L230 | ||
instructlab.sdg.generate_data( | ||
client=client, | ||
num_instructions_to_generate=num_instructions_to_generate, | ||
output_dir=sdg_path, | ||
taxonomy=taxonomy_path, | ||
taxonomy_base=taxonomy_base, | ||
model_name=model, | ||
pipeline=pipeline, | ||
chunk_word_count=1000, | ||
server_ctx_size=4096, | ||
) | ||
# Tweak precomputed skills data ratio if needed | ||
else: | ||
skills_recipe = "/usr/share/instructlab/sdg/default_data_recipes/skills.yaml" | ||
|
||
def set_precomputed_skills_data_ratio(sampling_size: float, skills_recipe: str): | ||
if path.exists(skills_recipe): | ||
with open(skills_recipe, "r", encoding="utf-8") as file: | ||
skills_yaml = yaml.load(file, Loader=yaml.Loader) | ||
|
||
skills_yaml["datasets"][0]["sampling_size"] = sampling_size | ||
|
||
with open(skills_recipe, "w", encoding="utf-8") as file: | ||
yaml.dump(skills_yaml, file) | ||
|
||
try: | ||
set_precomputed_skills_data_ratio( | ||
sampling_size=sdg_sampling_size, skills_recipe=skills_recipe | ||
) | ||
except PermissionError: | ||
print("Failed to set precomputed skills data ratio: Permission denied") | ||
print("Attempting to move default data recipes to temporary directory") | ||
import os | ||
import shutil | ||
import tempfile | ||
|
||
import xdg_base_dirs | ||
|
||
# Create a temporary directory | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
# Create a default_data_recipes directory | ||
temp_dir = path.join(temp_dir, "default_data_recipes") | ||
os.mkdir(temp_dir) | ||
|
||
# Copy default_data_recipes/skills.yaml to the temporary directory | ||
shutil.copy(skills_recipe, temp_dir) | ||
|
||
# Also copy the current pipeline directory to the temporary directory - it's a small | ||
# directory like 28KB | ||
# This isn't needed if the pipeline is either "full" or "simple" but it's future-proofing | ||
data_dirs = [ | ||
os.path.join(str(dir), "instructlab", "sdg") | ||
for dir in xdg_base_dirs.xdg_data_dirs() | ||
] | ||
temp_pipeline_dir = path.join(temp_dir, "pipeline") | ||
os.mkdir(temp_pipeline_dir) | ||
for d in data_dirs: | ||
pipeline_path = os.path.join(d, "pipelines", pipeline) | ||
if os.path.exists(pipeline_path): | ||
shutil.copytree( | ||
pipeline_path, | ||
temp_pipeline_dir, | ||
dirs_exist_ok=True, | ||
) | ||
break | ||
|
||
# Build new skills.yaml path | ||
new_skills_recipe = path.join(temp_dir, "skills.yaml") | ||
print(f"New skills recipe path: {new_skills_recipe}") | ||
|
||
# Override XDG_DATA_DIRS with the temporary directory | ||
# This allows SDG to read the new skills.yaml since it's looking into XDG_DATA_DIRS | ||
# and looks for a default_data_recipes directory with a skills.yaml file | ||
os.environ["XDG_DATA_DIRS"] = f"{temp_dir}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep the override here instead of doing |
||
|
||
# Try to set the precomputed skills data ratio again | ||
try: | ||
set_precomputed_skills_data_ratio( | ||
sampling_size=sdg_sampling_size, skills_recipe=new_skills_recipe | ||
) | ||
print( | ||
f"Successfully set precomputed skills data ratio to {sdg_sampling_size}" | ||
) | ||
|
||
# generate_data has a magic word for its taxonomy_base argument - 'empty' | ||
# it allows generating from the whole repo, see: | ||
# https://github.com/instructlab/sdg/blob/c6a9e74a1618b1077cd38e713b8aaed8b7c0c8ce/src/instructlab/sdg/utils/taxonomy.py#L230 | ||
instructlab.sdg.generate_data( | ||
client=client, | ||
num_instructions_to_generate=num_instructions_to_generate, | ||
output_dir=sdg_path, | ||
taxonomy=taxonomy_path, | ||
taxonomy_base=taxonomy_base, | ||
model_name=model, | ||
pipeline=pipeline, | ||
chunk_word_count=1000, | ||
server_ctx_size=4096, | ||
) | ||
except Exception as e: | ||
print(f"Failed to set precomputed skills data ratio: {e}") | ||
raise | ||
|
||
|
||
@dsl.container_component | ||
def taxonomy_to_artifact_op( | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
PYTHON_IMAGE = "quay.io/modh/odh-generic-data-science-notebook:v3-2024b-20241111" | ||
TOOLBOX_IMAGE = "registry.access.redhat.com/ubi9/toolbox" | ||
OC_IMAGE = "registry.redhat.io/openshift4/ose-cli" | ||
RHELAI_IMAGE = "quay.io/redhat-et/ilab:1.2" | ||
RHELAI_IMAGE = "quay.io/redhat-et/ilab:1.3" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add more explanation for this since it differs from what's exposed in ilab CLI? Or, link to an issue to replace this once the equivalent is in ilab/sdg? This can be a follow-up.