Skip to content

Minor cleanup in torchchat/cli/builder.py #1308

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

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions torchchat/cli/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,16 @@ def __post_init__(self):
if self.dso_path and self.pte_path:
raise RuntimeError("specify either DSO path or PTE path, but not both")

if self.checkpoint_path and (self.dso_path or self.pte_path):
print(
"Warning: checkpoint path ignored because an exported DSO or PTE path specified"
)
if self.checkpoint_dir and (self.dso_path or self.pte_path):
print(
"Warning: checkpoint dir ignored because an exported DSO or PTE path specified"
)
if self.gguf_path and (self.dso_path or self.pte_path):
print(
"Warning: GGUF path ignored because an exported DSO or PTE path specified"
)
if not (self.dso_path) and not (self.pte_path):
if self.dso_path or self.pte_path:
ignored_params = [
(self.checkpoint_path, "checkpoint path"),
(self.checkpoint_dir, "checkpoint dir"),
(self.gguf_path, "GGUF path"),
]
for param, param_msg in ignored_params:
if param:
print(f"Warning: {param_msg} ignored because an exported DSO or PTE path was specified")
else:
self.prefill_possible = True

@classmethod
Expand Down Expand Up @@ -446,7 +443,7 @@ def _maybe_init_distributed(
return world_mesh, parallel_dims


def _maybe_parellelize_model(
def _maybe_parallelize_model(
model: nn.Module,
builder_args: BuilderArgs,
world_mesh: DeviceMesh,
Expand Down Expand Up @@ -486,7 +483,7 @@ def _load_model(builder_args: BuilderArgs) -> Model:
model = _init_model_on_meta_device(builder_args)
else:
model = _load_model_default(builder_args)
model = _maybe_parellelize_model(model, builder_args, world_mesh, parallel_dims)
model = _maybe_parallelize_model(model, builder_args, world_mesh, parallel_dims)

model = model.to(device=builder_args.device, dtype=builder_args.precision)
return model.eval()
Expand Down
Loading