Amazon S3 Transfer Acceleration を利用して、カスタムモデルインポートで必要な S3 バケットへのアップロード時間を短縮してみた

Amazon S3 Transfer Acceleration を利用して、カスタムモデルインポートで必要な S3 バケットへのアップロード時間を短縮してみた

Clock Icon2025.02.01

こんにちは!クラウド事業本部コンサルティング部のたかくに(@takakuni_)です。

最近、 100, 200 GB くらいですが、大きめのファイルを S3 に日本からバージニア北部リージョンの S3 バケットへアップロードする機会がありました。

https://dev.classmethod.jp/articles/try-amazon-bedrock-custom-model-import/

私が接続しているネットワークの状況にもよりますが、 S3 へのアップロードだけで多くの時間がかかってしまうため、どうにか解消したいと思いました。

どうやら Amazon S3 Transfer Acceleration を使えば解決できそうなので、試してみたいと思います。

Amazon S3 Transfer Acceleration

Amazon S3 Transfer Acceleration はバケット単位で設定する機能で、クライアントと S3 バケット間の長距離のファイル転送を高速、簡単、安全に行う機能です。エッジローケーションを経由し AWS のバックボーンネットワークを利用することでファイル転送を高速化させます。

Untitled(106).png

https://aws.amazon.com/jp/s3/transfer-acceleration/

スピード比較ツールというものがあるみたいで、事前にどれくらい早くなるのか参考値が見られるサイトも用意されています。

https://s3-accelerate-speedtest.s3-accelerate.amazonaws.com/en/accelerate-speed-comparsion.html

サイトによると私の場合、バージニアリージョンは転送速度が 99 % 早くなるそうです。(その下のオレゴンやダブリンも、なかなかの速度差異がありますね。)

2024-12-25 at 09.47.20-s3-accelerate-speedtest.s3-accelerate.amazonaws.comenaccelerate-speed-comparsion.html@2x.png

東京やソウルリージョンなど地理的に近いリージョンだと効果が見込めない、返って遅くなるケースがあるようです。興味深いですね。

2024-12-25 at 10.09.56-s3-accelerate-speedtest.s3-accelerate.amazonaws.comenaccelerate-speed-comparsion.html.png

料金

通常、 S3 バケットのデータインは無料ですが、 Transfer Acceleration を利用すると、データインにデータ転送料がかかります。

料金表によると 米国、欧州、日本の AWS エッジロケーションによる高速化 を利用した場合、 1GB あたり 0.04 USD/GB 発生するようです。

インターネットから Amazon S3 へのデータ転送受信 (イン):
米国、欧州、日本の AWS エッジロケーションによる高速化 0.04 USD/GB

https://aws.amazon.com/jp/s3/pricing/

前提条件

サポートしているリージョンは以下の通りです。

  • Asia Pacific (Tokyo) (ap-northeast-1)
  • Asia Pacific (Seoul) (ap-northeast-2)
  • Asia Pacific (Mumbai) (ap-south-1)
  • Asia Pacific (Singapore) (ap-southeast-1)
  • Asia Pacific (Sydney) (ap-southeast-2)
  • Canada (Central) (ca-central-1)
  • Europe (Frankfurt) (eu-central-1)
  • Europe (Ireland) (eu-west-1)
  • Europe (London) (eu-west-2)
  • Europe (Paris) (eu-west-3)
  • South America (São Paulo) (sa-east-1)
  • US East (N. Virginia) (us-east-1)
  • US East (Ohio) (us-east-2)
  • US West (N. California) (us-west-1)
  • US West (Oregon) (us-west-2)

おそらく大丈夫だとは思いますが、アクセスは仮想ホスト形式のみでパス形式のサポートはされていません。

https://dev.classmethod.jp/articles/s3-no-longer-support-path-style-requests/

バケット名にはピリオド . が含まれていないバケット名である必要があります。オブジェクトアップロード前に事前に S3 バケットに対して、Transfer Acceleration を有効にしておく必要があります。

  • Transfer Acceleration は仮想ホスト形式のリクエストでのみサポートされます。仮想ホスト形式のリクエストの詳細については、「Amazon S3 API リファレンス」の「Making requests using the REST API」を参照してください。
  • Transfer Acceleration で使用するバケットは、ピリオド (".") が含まれていない DNS 準拠の名前にする必要があります。
  • Transfer Acceleration は、バケットに対して有効にする必要があります。詳細については、[S3 Transfer Acceleration の有効化と使用] を参照してください。
  • バケットで Transfer Acceleration を有効にした後、バケットへのデータ転送速度が上昇するまでに最大 20 分かかることがあります。

https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/userguide/transfer-acceleration.html#transfer-acceleration-requirements

やってみる

それでは Transfer Acceleration を利用して、どれほど早くなるのか試してみたいと思います。

Transfer Acceleration の有効化

対象の S3 バケットを選択しプロパティ欄から Transfer Acceleration を有効化します。

2024-12-23 at 21.21.07-Transfer Acceleration を編集 - S3 バケット model-import-123456789012  S3  us-east-1.png

S3 バケットで設定が有効になっていれば OK です。ドキュメントに最大 20 分反映に時間がかかるそうなので、気長に待ちましょう。

2024-12-23 at 21.21.55-model-import-123456789012 - S3 バケット  S3  us-east-1 2.png

素材のダウンロード

Hugging Face からモデル(DeepSeek-R1-Distill-Qwen-32B-Japanese)をダウンロードします。

git-lfs をインストールしていない場合は、事前に済ませておきましょう。

# Make sure you have git-lfs installed (https://git-lfs.com)
git lfs install

# モデルのダウンロード
nohup time git clone https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Llama-70B > hugging_face.log &

不要なファイルは削除しておきます。

rm -rf DeepSeek-R1-Distill-Llama-70B/.git

ディレクトリの合計は 132 GB になりました。

takakuni@ Downloads % du -h
760K    ./DeepSeek-R1-Distill-Llama-70B/figures
131G    ./DeepSeek-R1-Distill-Llama-70B
132G    .

S3 へのアップロード

時間を測りながら、 S3 バケットに対してモデルデータのアップロードを行います。

まずは通常のエンドポイント経由で渡してみます。

nohup time aws s3 sync DeepSeek-R1-Distill-Llama-70B s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B > default_endpoint.log &

トータル 1 時間半ほど経過しました。

upload: DeepSeek-R1-Distill-Llama-70B/.gitattributes to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/.gitattributes
upload: DeepSeek-R1-Distill-Llama-70B/config.json to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/config.json
upload: DeepSeek-R1-Distill-Llama-70B/generation_config.json to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/generation_config.json
upload: DeepSeek-R1-Distill-Llama-70B/LICENSE to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/LICENSE
upload: DeepSeek-R1-Distill-Llama-70B/.DS_Store to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/.DS_Store
upload: DeepSeek-R1-Distill-Llama-70B/README.md to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/README.md
upload: DeepSeek-R1-Distill-Llama-70B/figures/benchmark.jpg to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/figures/benchmark.jpg
upload: DeepSeek-R1-Distill-Llama-70B/model-00003-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00003-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00005-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00005-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00004-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00004-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00002-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00002-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00001-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00001-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00006-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00006-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00007-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00007-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00009-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00009-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00008-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00008-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00010-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00010-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00011-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00011-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00012-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00012-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00013-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00013-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model.safetensors.index.json to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model.safetensors.index.json
upload: DeepSeek-R1-Distill-Llama-70B/tokenizer_config.json to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/tokenizer_config.json
upload: DeepSeek-R1-Distill-Llama-70B/tokenizer.json to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/tokenizer.json
upload: DeepSeek-R1-Distill-Llama-70B/model-00014-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00014-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00015-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00015-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00016-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00016-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00017-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00017-of-000017.safetensors
     5344.37 real       620.09 user       499.85 sys

続いて Transfer Acceleration 経由で渡してみます。

nohup time aws s3 sync DeepSeek-R1-Distill-Llama-70B s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B --endpoint https://s3-accelerate.amazonaws.com > transfer_endpoint.log &

約 27 分短縮されました。単純計算で 30 % ほど時間をカットできていますね。

upload: DeepSeek-R1-Distill-Llama-70B/LICENSE to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/LICENSE
upload: DeepSeek-R1-Distill-Llama-70B/config.json to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/config.json
upload: DeepSeek-R1-Distill-Llama-70B/generation_config.json to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/generation_config.json
upload: DeepSeek-R1-Distill-Llama-70B/.gitattributes to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/.gitattributes
upload: DeepSeek-R1-Distill-Llama-70B/.DS_Store to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/.DS_Store
upload: DeepSeek-R1-Distill-Llama-70B/README.md to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/README.md
upload: DeepSeek-R1-Distill-Llama-70B/figures/benchmark.jpg to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/figures/benchmark.jpg
upload: DeepSeek-R1-Distill-Llama-70B/model-00003-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00003-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00005-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00005-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00004-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00004-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00002-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00002-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00001-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00001-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00006-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00006-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00007-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00007-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00009-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00009-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00008-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00008-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00010-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00010-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00011-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00011-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00012-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00012-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model.safetensors.index.json to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model.safetensors.index.json
upload: DeepSeek-R1-Distill-Llama-70B/model-00013-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00013-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/tokenizer.json to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/tokenizer.json
upload: DeepSeek-R1-Distill-Llama-70B/tokenizer_config.json to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/tokenizer_config.json
upload: DeepSeek-R1-Distill-Llama-70B/model-00015-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00015-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00014-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00014-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00016-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00016-of-000017.safetensors
upload: DeepSeek-R1-Distill-Llama-70B/model-00017-of-000017.safetensors to s3://model-import-123456789012/DeepSeek-R1-Distill-Llama-70B/model-00017-of-000017.safetensors
     3715.84 real       605.03 user       490.52 sys

まとめ

以上、「Amazon S3 Transfer Acceleration を利用して、カスタムモデルインポートで必要な S3 バケットへのアップロード時間を短縮してみた」でした。

今回、130GB ほどのサイズだったため、 0.04 * 130 GB = $5.2 ほど 27 分のために利用しました。

もっとファイルサイズが大きいやり取りが発生する場合は、より時間短縮が見込めたり、複数回実施する場合は検討の余地があるかも知れません。

そもそも、S3 とのファイルのやり取りを VPC 内(インターネットを使わずにやり取り)できれば、もっと早くなりそうですね。

このブログがどなたかの参考になれば幸いです。クラウド事業本部コンサルティング部のたかくに(@takakuni_)でした!

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.