Repository navigation
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 49e526617d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| revision_hashes = [rev.commit_hash for rev in target_repo.revisions] | ||
| if revision_hashes and hf_cache is not None: | ||
| delete_strategy = hf_cache.delete_revisions(*revision_hashes) |
There was a problem hiding this comment.
Respect GGUF variant when updating cached models
When /api/models/update-model is called with a variant for a GGUF repo, this code still builds revision_hashes from every cached revision and passes them all to delete_revisions, so updating one quant removes the entire cached repo (and any other quants) instead of only the requested variant described by the endpoint. This can unexpectedly evict other downloaded GGUF variants and force large re-downloads for users who keep multiple quants of the same repo.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Code Review
This pull request introduces AWS S3 dataset configuration support for training, adds backend endpoints to check for model updates and update cached models, and implements a new "Model Manager" tab in the frontend settings. The review feedback highlights several critical issues: the update_cached_model endpoint ignores the variant parameter and destructively deletes the entire model repository; both check_model_updates and update_cached_model are defined as async def but perform synchronous blocking operations that block the FastAPI event loop; and a useEffect hook in the frontend ModelsTab is missing required dependencies.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| hf_cache = scan | ||
| break | ||
| if target_repo is not None: | ||
| break | ||
|
|
||
| if target_repo is None: | ||
| raise HTTPException(status_code = 404, detail = "Model not found in cache") | ||
|
|
||
| # Delete old revisions |
There was a problem hiding this comment.
The update_cached_model endpoint accepts a variant parameter to update only a specific GGUF quantization variant, as documented in its docstring. However, the current implementation completely ignores this parameter and deletes the entire model repository (all revisions) from the cache. This is highly destructive and contrary to the intended behavior.
We should conditionally perform a per-variant deletion if variant is provided, matching the logic used in delete_cached_model.
if variant:
deleted_count = 0
for rev in target_repo.revisions:
for f in rev.files:
if not _is_gguf_filename(f.file_name):
continue
quant = _extract_quant_label(f.file_name)
if quant.lower() != variant.lower():
continue
try:
blob = Path(f.blob_path)
snap = Path(f.file_path)
if snap.exists() or snap.is_symlink():
snap.unlink()
if blob.exists():
blob.unlink()
deleted_count += 1
except Exception as e:
logger.warning(f"Failed to delete {f.file_name}: {e}")
if deleted_count == 0:
raise HTTPException(
status_code = 404,
detail = f"Variant {variant} not found in cache for {repo_id}",
)
else:
# Delete old revisions
revision_hashes = [rev.commit_hash for rev in target_repo.revisions]
if revision_hashes and hf_cache is not None:
delete_strategy = hf_cache.delete_revisions(*revision_hashes)
logger.info(
f"Deleting old version of {repo_id}: "
f"{delete_strategy.expected_freed_size_str} will be freed"
)
delete_strategy.execute()|
|
||
|
|
||
| @router.post("/check-updates") | ||
| async def check_model_updates( |
There was a problem hiding this comment.
The check_model_updates endpoint is defined as async def but performs synchronous blocking network I/O (hf_model_info). In FastAPI, running synchronous blocking calls inside an async def handler blocks the single-threaded event loop, preventing other requests from being processed.
Since there are no await calls inside this function, defining it as a standard synchronous def will instruct FastAPI to automatically run it in an external threadpool, avoiding any event loop blocking.
| async def check_model_updates( | |
| def check_model_updates( |
| ) | ||
| except Exception as e: | ||
| logger.debug(f"Could not check updates for {repo_id}: {e}") | ||
| continue |
There was a problem hiding this comment.
The update_cached_model endpoint is defined as async def but performs synchronous blocking file system operations (such as scanning the cache and deleting files). In FastAPI, running synchronous blocking calls inside an async def handler blocks the single-threaded event loop.
Since there are no await calls inside this function, defining it as a standard synchronous def will instruct FastAPI to automatically run it in an external threadpool, avoiding any event loop blocking.
| continue | |
| def update_cached_model( |
| if (!loading && allModels.length > 0 && updates.size === 0) { | ||
| checkForUpdates(); | ||
| } | ||
| }, [loading, allModels.length]); | ||
|
|
There was a problem hiding this comment.
The useEffect hook calls checkForUpdates but omits it from its dependency array. This violates the react-hooks/exhaustive-deps lint rule and can lead to stale closures or unexpected behavior if the function's dependencies change.
Including checkForUpdates and updates.size in the dependency array ensures that the effect correctly reacts to changes and adheres to React best practices.
useEffect(() => {
if (!loading && allModels.length > 0 && updates.size === 0) {
checkForUpdates();
}
}, [loading, allModels.length, checkForUpdates, updates.size]);
Add foundational types and configuration for S3 bucket dataset loading: - Add S3Config type to frontend training types - Add S3Config Pydantic model to backend training models - Add "s3" as a DatasetSource option - Add s3Config state and setS3Config action to training config store - Add i18n translations for S3 configuration (English and Chinese) This provides the type definitions and UI text for S3 integration. Full implementation requires boto3 dependency and data loading logic. Refs: unslothai#4539
49e5266 to
2bc2566
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 654ddb65c3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| ) | ||
|
|
||
| # S3 dataset source configuration | ||
| s3_config: Optional[S3Config] = Field( |
There was a problem hiding this comment.
Wire S3 requests into training startup
When an API client follows the new s3_config field exposed by TrainingStartRequest, the value is accepted by FastAPI but never copied into training_kwargs; the worker still only checks hf_dataset or local_datasets and otherwise raises ValueError("No dataset specified"). In the direct /api/training/start S3 scenario, this makes the advertised S3 dataset configuration a no-op instead of loading from S3 or rejecting the request before queuing.
Useful? React with 👍 / 👎.
| setFinetuneMLPModules: (finetuneMLPModules) => | ||
| set({ finetuneMLPModules }), | ||
| setTargetModules: (targetModules) => set({ targetModules }), | ||
| setS3Config: (s3Config) => set({ s3Config }), |
There was a problem hiding this comment.
Keep S3 secrets out of persisted config
When a future S3 form calls this setter with access-key credentials, s3Config is not listed in NON_PERSISTED_STATE_KEYS, so the store's partializePersistedState will write the whole object, including secretAccessKey, into the unsloth_training_config_v1 persisted browser storage. That exposes AWS secrets across reloads and to any script with access to local storage; either exclude this field from persistence or persist only non-secret S3 metadata.
Useful? React with 👍 / 👎.
- Pass s3_config from request into training_kwargs so it flows to training subprocess - Add s3Config to NON_PERSISTED_STATE_KEYS to prevent AWS secrets from being saved to localStorage Addresses code review feedback on PR unslothai#5951.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0fe44eb5d4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| "resume_from_checkpoint": kwargs.get("resume_from_checkpoint"), | ||
| "trust_remote_code": kwargs.get("trust_remote_code", False), | ||
| "gpu_ids": kwargs.get("gpu_ids"), | ||
| "s3_config": kwargs.get("s3_config"), |
There was a problem hiding this comment.
Scrub S3 secrets before persisting run config
When s3_config includes access-key credentials, adding the whole object to the training config causes secret_access_key to survive the later _db_config = {k: v for k, v in config.items() if k not in {"hf_token", "wandb_token"}} filter and be written as config_json in the training_runs table. This means starting a training job with S3 credentials stores the AWS secret in the Studio DB/history; the nested S3 secret should be removed or redacted before _db_config is created.
Useful? React with 👍 / 👎.
Filter out s3_config (which contains secret_access_key) from the config_json stored in training_runs table, preventing AWS credentials from being persisted to disk. Addresses P1 security feedback on PR unslothai#5951.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c87a7433e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
| export type StepNumber = 1 | 2 | 3 | 4 | 5; | ||
| export type DatasetSource = "huggingface" | "upload"; | ||
| export type DatasetSource = "huggingface" | "upload" | "s3"; |
There was a problem hiding this comment.
Keep the dataset source union buildable
Adding "s3" to DatasetSource widens config.datasetSource, but StudioPage still passes that value to DatasetPreviewDialog, whose datasetSource prop only accepts "huggingface" | "upload". In the frontend's strict TypeScript build (build runs tsc -b), this assignment is no longer type-compatible, so the app fails typecheck even when no S3 UI is used; either update the dialog prop/handling for S3 or narrow the value before passing it.
Useful? React with 👍 / 👎.
| if request.s3_config is not None: | ||
| raise HTTPException( | ||
| status_code = 501, |
There was a problem hiding this comment.
Let the S3 rejection reach the client
When s3_config is present, this HTTPException(501) is raised inside the route's broad try, but start_training only catches ValueError and then Exception, so the exception is converted by the final handler into a generic 500 Failed to start training response. This defeats the explicit not-implemented rejection for S3 requests; add an except HTTPException: raise path (as other routes do) or move this check outside the broad catch.
Useful? React with 👍 / 👎.
|
Thanks for the PR. I synced the branch with main and pushed two changes on top.
Keeping the DB exclusion you added, that part was right. For this to be mergeable it needs the actual loader: download from the bucket into the local datasets dir (boto3 as an optional import) and feed the files through the existing local_datasets path, plus a UI panel that actually sends s3Config. As is, the field is unreachable from the frontend. Are you planning to build that part? If not I can take it over. |
|
Thanks for the PR - sadly it's still not ready yet, so will close for now |
|
Follow-ups from a review pass, pushed in two commits:
|
* feat(studio): add S3 dataset configuration foundation (#4539) Add foundational types and configuration for S3 bucket dataset loading: - Add S3Config type to frontend training types - Add S3Config Pydantic model to backend training models - Add "s3" as a DatasetSource option - Add s3Config state and setS3Config action to training config store - Add i18n translations for S3 configuration (English and Chinese) This provides the type definitions and UI text for S3 integration. Full implementation requires boto3 dependency and data loading logic. Refs: #4539 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Wire S3 config into training pipeline and prevent secrets persistence - Pass s3_config from request into training_kwargs so it flows to training subprocess - Add s3Config to NON_PERSISTED_STATE_KEYS to prevent AWS secrets from being saved to localStorage Addresses code review feedback on PR #5951. * Exclude S3 config from database persistence to protect secrets Filter out s3_config (which contains secret_access_key) from the config_json stored in training_runs table, preventing AWS credentials from being persisted to disk. Addresses P1 security feedback on PR #5951. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Re-raise HTTPException in start_training and defer s3 DatasetSource widening for PR #5951 * Redact s3_config from W&B run config and accept camelCase S3 credential aliases for PR #5951 * feat(studio): implement S3 dataset loading end-to-end Builds the actual S3 loader on top of the hardened #5951 foundation, turning the 501-gated scaffold into a working dataset source. Backend: - Add core/training/s3_dataset.py: lists and downloads supported dataset files (parquet/json/jsonl/csv) from an S3 bucket to a temp dir, using IAM-role or access-key credentials. boto3 is imported lazily (optional dep). - Wire s3_config into UnslothTrainer.load_and_format_dataset (downloads then reuses the existing local-file path) and thread it through worker.py. - Replace the 501 "not implemented" gate with a boto3-availability guard so S3 works when boto3 is present and fails clearly when it is not. - Add boto3 to studio.txt requirements. - Add tests/test_s3_dataset.py (8 tests) covering download/filtering, collisions, missing-boto3, and S3Config camelCase/IAM validation. Frontend: - Widen DatasetSource to include "s3"; add s3_config to the training payload type and mapper; add an S3 validation branch and selectS3Source store action. - Add s3-config-form.tsx (bucket/region/prefix/keys/IAM toggle) reusing the existing studio.dataset.s3.* i18n strings. - Add a Hugging Face / Local / Amazon S3 source toggle in dataset-section; the S3 config card replaces the dataset combobox when S3 is selected. - Fix DatasetPreviewDialog to accept the widened DatasetSource type. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix S3 dataset loader for PR #6222 * Fix S3 dataset edge cases for PR #6222 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix S3 IAM payload handling for PR #6222 * Block multimodal S3 datasets for PR #6222 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han <[email protected]> Co-authored-by: Ash <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: wasimysaid <[email protected]>
Summary
Note
This is a partial implementation of #4539 that provides the type foundation. Full S3 integration requires:
This PR enables other developers to build on this foundation.
Test plan
Refs: #4539