-
-
Notifications
You must be signed in to change notification settings - Fork 503
Add Z Image LoRA fine tuning support #1127
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
Closed
Closed
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
a25e3a1
Add Z Image LoRA fine tuning support
ParamThakkar123 5c15019
Added existing parameter loading
ParamThakkar123 2b7c286
Updates
ParamThakkar123 038552a
Merge branch 'main' of https://github.com/transformerlab/transformerl…
ParamThakkar123 d571ab8
Merge branch 'main' into add/z-image-ft
josh-janes e334552
Merge branch 'main' into add/z-image-ft
dadmobile 222a669
Merge branch 'main' into add/z-image-ft
dadmobile ddd7319
Merge branch 'main' into add/z-image-ft
deep1401 efada1f
Updated ZImage fine tuning code
ParamThakkar123 2f2f9ee
Merge branch 'add/z-image-ft' of https://github.com/transformerlab/tr…
ParamThakkar123 5100330
Updated ZImage fine tuning code
ParamThakkar123 ef967b0
Updated ZImage fine tuning code
ParamThakkar123 e3262d2
Merge branch 'main' of https://github.com/transformerlab/transformerl…
ParamThakkar123 19f23a6
Reformat and rebase
ParamThakkar123 cc2a21d
Updates
ParamThakkar123 5c81506
Updates
ParamThakkar123 3c6c374
Updates
ParamThakkar123 d6f2822
Merge branch 'main' of https://github.com/transformerlab/transformerl…
ParamThakkar123 99e483e
Updates
ParamThakkar123 a2f85e9
Fixed saving lora weights
ParamThakkar123 d73e250
Formatting
ParamThakkar123 c1044c7
Merge branch 'main' of https://github.com/transformerlab/transformerl…
ParamThakkar123 63160e3
ruff
dadmobile 4c9ec6c
Merge branch 'main' into add/z-image-ft
dadmobile f798019
Merge branch 'main' into add/z-image-ft
ParamThakkar123 42418c4
Merge branch 'main' into add/z-image-ft
ParamThakkar123 2d3a814
Merge branch 'main' into add/z-image-ft
ParamThakkar123 79286da
updates
ParamThakkar123 6df347d
Merge branch 'main' into add/z-image-ft
ParamThakkar123 7072c16
Merge branch 'main' into add/z-image-ft
ParamThakkar123 281f25d
ruff
dadmobile 06b95c7
Merge remote-tracking branch 'origin/main' into add/z-image-ft
dadmobile 008f8ba
Merge branch 'main' of https://github.com/transformerlab/transformerl…
ParamThakkar123 fae56f9
Merge branch 'add/z-image-ft' of https://github.com/transformerlab/tr…
ParamThakkar123 1026537
Fixes
ParamThakkar123 0eacdb5
Fixes
ParamThakkar123 78f7d24
Updated Peft version
ParamThakkar123 69687cf
Fixes
ParamThakkar123 4425840
Fixes
ParamThakkar123 ddbc9e0
Fixes
ParamThakkar123 2914c12
Unpin versions
ParamThakkar123 f1061d5
Bump diffusion plugin version
dadmobile 9950ffd
Merge branch 'main' into add/z-image-ft
ParamThakkar123 973795c
Updates
ParamThakkar123 53a2895
Updates
ParamThakkar123 5a3f72c
Merge branch 'add/z-image-ft' of https://github.com/transformerlab/tr…
ParamThakkar123 87f465d
Merge branch 'main' of https://github.com/transformerlab/transformerl…
deep1401 edcb473
ruff
dadmobile 6cc7388
Merge branch 'main' into add/z-image-ft
ParamThakkar123 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -12,24 +12,115 @@ | |
| import sys | ||
| import argparse | ||
| import traceback | ||
| import asyncio | ||
| import sqlite3 | ||
| from typing import Optional | ||
|
|
||
|
|
||
| def get_db_config_value(key: str, team_id: Optional[str] = None, user_id: Optional[str] = None) -> Optional[str]: | ||
| """ | ||
| Read config values directly from sqlite without importing transformerlab.plugin. | ||
| This keeps harness startup independent from heavy ML dependencies. | ||
| """ | ||
| from lab import HOME_DIR | ||
|
|
||
| db_path = f"{HOME_DIR}/llmlab.sqlite3" | ||
| db = sqlite3.connect(db_path, isolation_level=None) | ||
| db.execute("PRAGMA busy_timeout=30000") | ||
| try: | ||
| # Priority 1: user-specific config (requires both user_id and team_id) | ||
| if user_id and team_id: | ||
| cursor = db.execute( | ||
| "SELECT value FROM config WHERE key = ? AND user_id = ? AND team_id = ?", (key, user_id, team_id) | ||
| ) | ||
| row = cursor.fetchone() | ||
| cursor.close() | ||
| if row is not None: | ||
| return row[0] | ||
|
|
||
| # Priority 2: team-wide config | ||
| if team_id: | ||
| cursor = db.execute( | ||
| "SELECT value FROM config WHERE key = ? AND user_id IS NULL AND team_id = ?", (key, team_id) | ||
| ) | ||
| row = cursor.fetchone() | ||
| cursor.close() | ||
| if row is not None: | ||
| return row[0] | ||
|
|
||
| # Priority 3: global config | ||
| cursor = db.execute("SELECT value FROM config WHERE key = ? AND user_id IS NULL AND team_id IS NULL", (key,)) | ||
| row = cursor.fetchone() | ||
| cursor.close() | ||
| return row[0] if row is not None else None | ||
| finally: | ||
| db.close() | ||
|
|
||
|
|
||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--plugin_dir", type=str, required=True) | ||
| args, unknown = parser.parse_known_args() | ||
|
|
||
|
|
||
| def set_config_env_vars(env_var: str, target_env_var: str = None, user_id: str = None, team_id: str = None): | ||
| try: | ||
| from transformerlab.plugin import get_db_config_value | ||
| def configure_plugin_runtime_library_paths(plugin_dir: str) -> None: | ||
| """ | ||
| Prefer CUDA/NCCL libraries from the plugin venv over system-wide libraries. | ||
| This reduces CUDA symbol mismatches caused by stale host NCCL installs. | ||
| """ | ||
| if os.name == "nt": | ||
| return | ||
|
|
||
| venv_path = os.path.join(plugin_dir, "venv") | ||
| if not os.path.isdir(venv_path): | ||
| return | ||
|
|
||
| pyver = f"python{sys.version_info.major}.{sys.version_info.minor}" | ||
| site_packages = os.path.join(venv_path, "lib", pyver, "site-packages") | ||
|
|
||
| candidate_paths: list[str] = [] | ||
| torch_lib = os.path.join(site_packages, "torch", "lib") | ||
| if os.path.isdir(torch_lib): | ||
| candidate_paths.append(torch_lib) | ||
|
|
||
| nvidia_root = os.path.join(site_packages, "nvidia") | ||
| if os.path.isdir(nvidia_root): | ||
| for pkg_name in os.listdir(nvidia_root): | ||
| lib_dir = os.path.join(nvidia_root, pkg_name, "lib") | ||
| if os.path.isdir(lib_dir): | ||
| candidate_paths.append(lib_dir) | ||
|
|
||
| value = asyncio.run(get_db_config_value(env_var, user_id=user_id, team_id=team_id)) | ||
| if not candidate_paths: | ||
| return | ||
|
|
||
| existing_paths = [p for p in os.environ.get("LD_LIBRARY_PATH", "").split(os.pathsep) if p] | ||
| candidate_norm = {os.path.normpath(c) for c in candidate_paths} | ||
|
|
||
| merged = list(candidate_paths) | ||
| for path in existing_paths: | ||
| if os.path.normpath(path) not in candidate_norm: | ||
| merged.append(path) | ||
|
|
||
| if merged != existing_paths: | ||
| os.environ["LD_LIBRARY_PATH"] = os.pathsep.join(merged) | ||
| print("Configured LD_LIBRARY_PATH for plugin runtime libraries") | ||
|
|
||
|
|
||
| configure_plugin_runtime_library_paths(args.plugin_dir) | ||
|
|
||
|
|
||
| def set_config_env_vars( | ||
| env_var: str, | ||
| target_env_var: Optional[str] = None, | ||
| user_id: Optional[str] = None, | ||
| team_id: Optional[str] = None, | ||
| ) -> None: | ||
| target_key = target_env_var or env_var | ||
| try: | ||
| value = get_db_config_value(env_var, user_id=user_id, team_id=team_id) | ||
| if value: | ||
| os.environ[target_env_var] = value | ||
| print(f"Set {target_env_var} from {'user' if user_id else 'team'} config: {value}") | ||
| os.environ[target_key] = value | ||
| print(f"Set {target_key} from {'user' if user_id else 'team'} config") | ||
| except Exception as e: | ||
| print(f"Warning: Could not set {target_env_var} from {'user' if user_id else 'team'} config: {e}") | ||
| print(f"Warning: Could not set {target_key} from {'user' if user_id else 'team'} config: {e}") | ||
|
|
||
|
|
||
| # Set organization context from environment variable if provided | ||
|
|
@@ -69,6 +160,11 @@ def set_config_env_vars(env_var: str, target_env_var: str = None, user_id: str = | |
| except ImportError as e: | ||
| print(f"Error executing plugin: {e}") | ||
| traceback.print_exc() | ||
| if "ncclCommShrink" in str(e): | ||
| print( | ||
| "Detected CUDA/NCCL mismatch while importing torch. " | ||
| "Reinstall the plugin venv with a torch build matching this machine's CUDA runtime." | ||
|
Member
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. We should never face this issue since we do the base install right? |
||
| ) | ||
|
|
||
| # if e is a ModuleNotFoundError, the plugin is missing a required package | ||
| if isinstance(e, ModuleNotFoundError): | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
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.
Why did you remove the import from transformerlab.plugin and add the function here directly? Was there an issue?