-
Notifications
You must be signed in to change notification settings - Fork 230
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
Integrate distributed inference with chat/server #1381
Integrate distributed inference with chat/server #1381
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchchat/1381
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 Pending, 1 Unrelated FailureAs of commit 7650153 with merge base 90749d2 (): NEW FAILURE - The following job has failed:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
torchchat/cli/builder.py
Outdated
"Meta-Llama-3-70B": "meta-llama/Meta-Llama-3-70B-Instruct", | ||
"Meta-Llama-3.1-70B": "meta-llama/Meta-Llama-3.1-70B-Instruct", | ||
|
||
} |
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.
What's the gap to using the models described in model_config/models.json
. (as implied by TODO comment)
Definitely should not be part of the present PR, but I think as a north star, it would be desirable to grab the same models (and download and mgmt infra etc) for non-distributed and distributed.
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.
Thanks for the comment @mikekgfb. The gap wasn't that big, the args.model just wasn't accessible at that point and I wanted to take a deeper look to fix it right. Removed the cruel hack and I now save the distribution_path when creating the builder_arg. Still not sure if this is the intended way of locating the checkpoint though.
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.
Not sure what you're trying to do. If it's just that the dict/json data structure describing the mapping isn't in scope, maybe what you want is some methods that give you the relevant info?
Also, these seem to be mapping of short names to HF network paths - should we not have a way to [ick them from the local filesystem (since the torchchat cli already manages download and all that). Oh, and if the answer is "we have bigger fish to fry, hooking this up is not highest priority" I will wholeheartedly agree. This is more about understanding the context of this PR.
Where I'm lacking the context is how you go from all the weights being available locally on a node to reading those weights on another node? And maybe that's why you prefer to straight up pick the files from HF? (Although local distribution from an already downloaded set of weights probs has higher bandwidth?) Again, there's much bigger fish to fry, and I think this PR is a good step in the direction of frying those fish ;)
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.
Oh I see, let me try to fill in some context for this PR. Previously, the distributed inference solution lived completely separate in its own script (within the torchchat repo but) separate from torchchat.py. Distributed provides its own utils to load either hf or torchchat weights (where the torchchat part is currently broken IIRC). In a previous PR (#1327), I enabled the usage of torchchat.py generate
with a distributed model. This PR only progresses the integration into the cli by enabling chat/server but stops short from replacing the weight loading mechanics which are still custom to distributed.
So, yes, for this PR I was only looking for a quick and dirty way to map arg.model_name -> "huggingface distribution str" (without actually having model_name at hand) to load the weights from the hf cache. I now modified the PR to use the information provided in the model_config/models.json as you suggested. In a next PR we should then alter torchchat/distributed/checkpoint_utils.py
to leverage torchchat infra like (e.g. builder_args) to locate and access the files.
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.
Partial review so far, still need to dig through generate
cc: @Gasoonjia as secondary reviewer
torchchat/generate.py
Outdated
@@ -358,7 +368,6 @@ def prefill( | |||
sequential_prefill=True, | |||
**sampling_kwargs, | |||
) -> torch.Tensor: | |||
# logging.debug(f"x: {x}, input_pos: {input_pos}") |
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.
Heads up the logging changes might get merge conflicted with #1336
torchchat/generate.py
Outdated
if self.pp_rank == self.last_pp_rank: | ||
new_token, next_prob = self.sample(logits, need_probs=need_probs, **sampling_kwargs) | ||
else: | ||
new_token = torch.zeros(1, 1, device=self.device, dtype=torch.int64) | ||
|
||
if self.pp_rank == self.last_pp_rank and self.pp_rank != self.first_pp_rank: | ||
dist.send( | ||
new_token, | ||
dst=self.first_pp_rank_global_id, | ||
group=self.pp_group, | ||
) | ||
elif self.pp_rank == self.first_pp_rank and self.pp_rank != self.last_pp_rank: | ||
dist.recv( | ||
new_token, | ||
src=self.last_pp_rank_global_id, | ||
group=self.pp_group, | ||
) | ||
#TODO: Why do we get 2d tensor here? | ||
new_token=new_token[0] |
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.
Ditto above as prefill
else: | ||
run_generator(args) |
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.
Shuold setup_env
also be triggering the generator?
Maybe it's just a naming change (run_with_setup~?), but setup_env doesn't make me think that the fn is called
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.
Yes, valid point. I've renamed it to run_in_dist_env to reflect that it runs the target as well as connecting it to distributed.
torchchat/generate.py
Outdated
from torchchat.distributed.generate import DistributedGenerator | ||
from torchchat.distributed.utils import ( | ||
Color as color, | ||
setup_env, |
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.
nit: setup_env
is pretty generic, let's alias it so it's obviously for a distributed context
torchchat/usages/server.py
Outdated
if builder_args.distributed: | ||
world_size = builder_args.tp * builder_args.pp | ||
mp_context = mp.get_context('spawn') | ||
queue = mp_context.Queue() | ||
|
||
if builder_args.distributed: |
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.
Identical conditional check
…inference_without_abstraction
Co-authored-by: Jack-Khuu <jack.khuu.7@gmail.com>
…n the comments as well
Should
|
@mikekgfb Yes, distributed generate was already working before this PR, thats why I did not list it separately. |
This PR integrates distributed inference with the CLI options chat and server and implements Option 2b of #1376.
To test run on machine with 4 gpus: