-
Notifications
You must be signed in to change notification settings - Fork 5
Add bandwidth limit feature for HTTP and S3 datasources #36
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
Open
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/fix-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
39586df
Initial plan
Copilot 0f1e503
Add bandwidth limit feature for HTTP and S3 datasources using rclone …
Copilot 44fc8e7
Fix YAML sample files to end with proper newlines
Copilot ebdb19d
Add bandwidth limiting with trickle for Git, HuggingFace, and ModelSc…
Copilot 333b1ef
Integrate trickle into Docker entrypoint for bandwidth limiting
Copilot 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
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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| apiVersion: dataset.baizeai.io/v1alpha1 | ||
| kind: Dataset | ||
| metadata: | ||
| name: git-dataset-with-bandwidth-limit | ||
| namespace: default | ||
| spec: | ||
| source: | ||
| type: GIT | ||
| uri: https://github.com/kubernetes/kubernetes.git | ||
| options: | ||
| branch: "master" | ||
| depth: "1" | ||
| bandwidthLimit: "5M" # Limit to 5 MiB/s | ||
| volumeClaimTemplate: | ||
| spec: | ||
| accessModes: | ||
| - ReadWriteOnce | ||
| resources: | ||
| requests: | ||
| storage: 10Gi |
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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| apiVersion: dataset.baizeai.io/v1alpha1 | ||
| kind: Dataset | ||
| metadata: | ||
| name: gpt2-train-data-limited | ||
| spec: | ||
| dataSyncRound: 1 | ||
| mountOptions: | ||
| gid: 1000 | ||
| mode: "0774" | ||
| path: / | ||
| uid: 1000 | ||
| source: | ||
| type: HTTP | ||
| uri: http://baize-ai.daocloud.io/gpt2-train-data/ | ||
| options: | ||
| bandwidthLimit: "10M" # Limit download bandwidth to 10 MiB/s |
20 changes: 20 additions & 0 deletions
20
config/samples/huggingface-dataset-with-bandwidth-limit.yaml
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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| apiVersion: dataset.baizeai.io/v1alpha1 | ||
| kind: Dataset | ||
| metadata: | ||
| name: huggingface-dataset-with-bandwidth-limit | ||
| namespace: default | ||
| spec: | ||
| source: | ||
| type: HUGGING_FACE | ||
| uri: huggingface://microsoft/DialoGPT-medium | ||
| options: | ||
| repoType: "model" | ||
| bandwidthLimit: "3M" # Limit to 3 MiB/s | ||
| secretRef: huggingface-credentials | ||
| volumeClaimTemplate: | ||
| spec: | ||
| accessModes: | ||
| - ReadWriteOnce | ||
| resources: | ||
| requests: | ||
| storage: 5Gi |
20 changes: 20 additions & 0 deletions
20
config/samples/modelscope-dataset-with-bandwidth-limit.yaml
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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| apiVersion: dataset.baizeai.io/v1alpha1 | ||
| kind: Dataset | ||
| metadata: | ||
| name: modelscope-dataset-with-bandwidth-limit | ||
| namespace: default | ||
| spec: | ||
| source: | ||
| type: MODEL_SCOPE | ||
| uri: modelscope://damo/nlp_structbert_backbone_base_std | ||
| options: | ||
| repoType: "model" | ||
| bandwidthLimit: "8M" # Limit to 8 MiB/s | ||
| secretRef: modelscope-credentials | ||
| volumeClaimTemplate: | ||
| spec: | ||
| accessModes: | ||
| - ReadWriteOnce | ||
| resources: | ||
| requests: | ||
| storage: 2Gi |
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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| apiVersion: dataset.baizeai.io/v1alpha1 | ||
| kind: Dataset | ||
| metadata: | ||
| name: s3-dataset-limited | ||
| spec: | ||
| dataSyncRound: 1 | ||
| mountOptions: | ||
| gid: 1000 | ||
| mode: "0774" | ||
| path: / | ||
| uid: 1000 | ||
| source: | ||
| type: S3 | ||
| uri: s3://my-bucket/models/ | ||
| options: | ||
| region: "us-east-1" | ||
| provider: "AWS" | ||
| bandwidthLimit: "5M" # Limit download bandwidth to 5 MiB/s | ||
| secretRef: s3-credentials |
Binary file not shown.
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 |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Function to convert bandwidth limit from rclone format to KB/s for trickle | ||
| convert_bandwidth_limit() { | ||
| local limit="$1" | ||
|
|
||
| if [[ -z "$limit" ]]; then | ||
| echo "0" | ||
| return | ||
| fi | ||
|
|
||
| # Extract number and suffix using regex | ||
| if [[ "$limit" =~ ^([0-9]+(\.[0-9]+)?)([BKMGTP]?)$ ]]; then | ||
| local number="${BASH_REMATCH[1]}" | ||
| local suffix="${BASH_REMATCH[3]^^}" # Convert to uppercase | ||
|
|
||
| # Convert to integer for bash arithmetic (handle decimal by multiplying by 1000 first) | ||
| local number_int | ||
| if [[ "$number" =~ \. ]]; then | ||
| # For decimal numbers, multiply by 1000 first then divide later | ||
| number_int=$(awk "BEGIN {print int($number * 1000)}") | ||
| local decimal_multiplier=1000 | ||
| else | ||
| number_int=$number | ||
| local decimal_multiplier=1 | ||
| fi | ||
|
|
||
| local bytes_per_second | ||
| case "$suffix" in | ||
| "B") | ||
| bytes_per_second=$((number_int / decimal_multiplier)) | ||
| ;; | ||
| ""|"K") | ||
| # Plain number defaults to KiB/s for rclone compatibility | ||
| bytes_per_second=$((number_int * 1024 / decimal_multiplier)) | ||
| ;; | ||
| "M") | ||
| bytes_per_second=$((number_int * 1024 * 1024 / decimal_multiplier)) | ||
| ;; | ||
| "G") | ||
| bytes_per_second=$((number_int * 1024 * 1024 * 1024 / decimal_multiplier)) | ||
| ;; | ||
| "T") | ||
| bytes_per_second=$((number_int * 1024 * 1024 * 1024 * 1024 / decimal_multiplier)) | ||
| ;; | ||
| "P") | ||
| bytes_per_second=$((number_int * 1024 * 1024 * 1024 * 1024 * 1024 / decimal_multiplier)) | ||
| ;; | ||
| *) | ||
| echo "Error: Unsupported suffix: $suffix" >&2 | ||
| echo "0" | ||
| return | ||
| ;; | ||
| esac | ||
|
|
||
| # Convert bytes per second to KB/s (1 KB = 1000 bytes for trickle) | ||
| local kbps=$((bytes_per_second / 1000)) | ||
|
|
||
| # Minimum 1 KB/s if > 0 | ||
| if [[ $bytes_per_second -gt 0 && $kbps -eq 0 ]]; then | ||
| kbps=1 | ||
| fi | ||
|
|
||
| echo "$kbps" | ||
| else | ||
| echo "Error: Invalid bandwidth limit format: $limit" >&2 | ||
| echo "0" | ||
| fi | ||
| } | ||
|
|
||
| # Check if bandwidth limit is set via environment variable | ||
| if [[ -n "$BANDWIDTH_LIMIT" ]]; then | ||
| echo "Bandwidth limit detected: $BANDWIDTH_LIMIT" | ||
|
|
||
| # Convert bandwidth limit to trickle format | ||
| kbps=$(convert_bandwidth_limit "$BANDWIDTH_LIMIT") | ||
|
|
||
| if [[ "$kbps" -gt 0 ]]; then | ||
| echo "Applying bandwidth limit: ${kbps} KB/s" | ||
| # Use trickle to wrap the data-loader command | ||
| exec trickle -d "$kbps" -u "$kbps" /usr/local/bin/data-loader "$@" | ||
| else | ||
| echo "Invalid or zero bandwidth limit, running without trickle" | ||
| exec /usr/local/bin/data-loader "$@" | ||
| fi | ||
| else | ||
| # No bandwidth limit, run data-loader directly | ||
| exec /usr/local/bin/data-loader "$@" | ||
| fi |
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
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
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
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.
Do you have any solutions for other types of Datasets?
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.
Same as above - bandwidth limiting can be extended to other dataset types beyond HTTP and S3, though implementation complexity varies. The current approach leverages rclone's built-in
--bwlimitflag, which is why it's straightforward for HTTP and S3. Other types would require external bandwidth limiting tools liketrickleor traffic control.