Skip to content

Commit f9cf345

Browse files
authored
Adding new env variables for TPU backends. (#1755)
# What does this PR do? On TPU (and probably inferentia). The model needs to know right off the bat about BATCH_SIZE and MAX_TOTAL_TOKENS (since the entire cache will be determined by both). This PR sends that information to the shards to they can allocate accordingly. Should be no-op for other backends. <!-- Congratulations! You've made it this far! You're not quite done yet though. Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution. Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change. Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost. --> <!-- Remove if not applicable --> Fixes # (issue) ## Before submitting - [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). - [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests), Pull Request section? - [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link to it if that's the case. - [ ] Did you make sure to update the documentation with your changes? Here are the [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation). - [ ] Did you write any new necessary tests? ## Who can review? Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR. <!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @ @OlivierDehaene OR @Narsil -->
1 parent bbc547a commit f9cf345

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

launcher/src/main.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ fn shard_manager(
448448
cuda_memory_fraction: f32,
449449
rope_scaling: Option<RopeScaling>,
450450
rope_factor: Option<f32>,
451+
max_total_tokens: usize,
452+
max_batch_size: Option<usize>,
451453
otlp_endpoint: Option<String>,
452454
status_sender: mpsc::Sender<ShardStatus>,
453455
shutdown: Arc<AtomicBool>,
@@ -512,6 +514,7 @@ fn shard_manager(
512514
(Some(scaling), Some(factor)) => Some((scaling, factor)),
513515
(None, Some(factor)) => Some((RopeScaling::Linear, factor)),
514516
};
517+
515518
// OpenTelemetry
516519
if let Some(otlp_endpoint) = otlp_endpoint {
517520
shard_args.push("--otlp-endpoint".to_string());
@@ -564,6 +567,14 @@ fn shard_manager(
564567
envs.push(("ROPE_FACTOR".into(), factor.to_string().into()));
565568
}
566569

570+
envs.push((
571+
"MAX_TOTAL_TOKENS".into(),
572+
max_total_tokens.to_string().into(),
573+
));
574+
if let Some(max_batch_size) = max_batch_size {
575+
envs.push(("MAX_BATCH_SIZE".into(), max_batch_size.to_string().into()));
576+
}
577+
567578
// If huggingface_hub_cache is some, pass it to the shard
568579
// Useful when running inside a docker container
569580
if let Some(huggingface_hub_cache) = huggingface_hub_cache {
@@ -967,6 +978,7 @@ fn spawn_shards(
967978
num_shard: usize,
968979
args: &Args,
969980
cuda_graphs: Vec<usize>,
981+
max_total_tokens: usize,
970982
shutdown: Arc<AtomicBool>,
971983
shutdown_receiver: &mpsc::Receiver<()>,
972984
shutdown_sender: mpsc::Sender<()>,
@@ -998,6 +1010,7 @@ fn spawn_shards(
9981010
let cuda_memory_fraction = args.cuda_memory_fraction;
9991011
let rope_scaling = args.rope_scaling;
10001012
let rope_factor = args.rope_factor;
1013+
let max_batch_size = args.max_batch_size;
10011014
thread::spawn(move || {
10021015
shard_manager(
10031016
model_id,
@@ -1020,6 +1033,8 @@ fn spawn_shards(
10201033
cuda_memory_fraction,
10211034
rope_scaling,
10221035
rope_factor,
1036+
max_total_tokens,
1037+
max_batch_size,
10231038
otlp_endpoint,
10241039
status_sender,
10251040
shutdown,
@@ -1474,6 +1489,7 @@ fn main() -> Result<(), LauncherError> {
14741489
num_shard,
14751490
&args,
14761491
cuda_graphs,
1492+
max_total_tokens,
14771493
shutdown.clone(),
14781494
&shutdown_receiver,
14791495
shutdown_sender,

0 commit comments

Comments
 (0)