Skip to content
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

chat mode improvements #244

Merged
merged 7 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 6 additions & 3 deletions .github/workflows/eager-dtype.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ jobs:
echo "******************************************"
echo "******** INT4 group-wise quantized *******"
echo "******************************************"

python generate.py --dtype ${DTYPE} --quant '{"linear:int4" : {"groupsize": 32}}' --checkpoint-path ${MODEL_PATH} --temperature 0 > ./output_eager
cat ./output_eager

echo "INT4 should work on MacOS on x86, but cannot be tested"
echo "because nightlies are too old!"

# python generate.py --dtype ${DTYPE} --quant '{"linear:int4" : {"groupsize": 32}}' --checkpoint-path ${MODEL_PATH} --temperature 0 > ./output_eager
# cat ./output_eager

echo "tests complete for ${DTYPE}"
done
Expand Down
22 changes: 21 additions & 1 deletion build/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class BuilderArgs:
precision: torch.dtype = torch.float32
setup_caches: bool = False
use_tp: bool = False

is_chat_model: bool = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to make that the default?


def __post_init__(self):
if not (
(self.checkpoint_path and self.checkpoint_path.is_file())
Expand Down Expand Up @@ -66,6 +67,24 @@ def __post_init__(self):

@classmethod
def from_args(cls, args): # -> BuilderArgs:
is_chat_model = False
if args.is_chat_model:
is_chat_model = True
else:
for path in [
args.checkpoint_path,
args.checkpoint_dir,
args.dso_path,
args.pte_path,
args.gguf_path
]:
path = str(path)
if path.endswith('/'):
path = path[:-1]
path_basename = os.path.basename(path)
if "chat" in path_basename:
is_chat_model = True

return cls(
checkpoint_path=args.checkpoint_path,
checkpoint_dir=args.checkpoint_dir,
Expand All @@ -78,6 +97,7 @@ def from_args(cls, args): # -> BuilderArgs:
precision=name_to_dtype(args.dtype),
setup_caches=(args.output_dso_path or args.output_pte_path),
use_tp=False,
is_chat_model=is_chat_model,
)

@classmethod
Expand Down
5 changes: 5 additions & 0 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def _add_arguments_common(parser):
action="store_true",
help="Use torchchat to for an interactive chat session.",
)
parser.add_argument(
"--is-chat-model",
action="store_true",
help="Use torchchat to for an interactive chat session.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't parse as written; delete "to"?

)
parser.add_argument(
"--gui",
action="store_true",
Expand Down
10 changes: 4 additions & 6 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from cli import add_arguments_for_generate, arg_init, check_args
from quantize import set_precision

B_INST, E_INST = "[INST]", "[/INST]"

@dataclass
class GeneratorArgs:
Expand Down Expand Up @@ -339,11 +340,8 @@ def _main(
set_precision(builder_args.precision)
is_speculative = speculative_builder_args.checkpoint_path is not None

is_chat = "chat" in str(os.path.basename(builder_args.checkpoint_path))
if is_chat:
raise RuntimeError(
"need to stop filename based kludgery, at a minimum need to look at all pathnames. in particular, this now fails because chat is part of the pathname, yuck!"
)
if generator_args.chat_mode and not builder_args.is_chat_model:
raise RuntimeError("You need to use --is-chat-model to indicate model has chat support.")

tokenizer = _initialize_tokenizer(tokenizer_args)

Expand Down Expand Up @@ -406,7 +404,7 @@ def _main(
device_sync(device=builder_args.device)
if i >= 0 and generator_args.chat_mode:
prompt = input("What is your prompt? ")
if is_chat:
if builder_args.is_chat_model:
prompt = f"{B_INST} {prompt.strip()} {E_INST}"
encoded = encode_tokens(
tokenizer, prompt, bos=True, device=builder_args.device
Expand Down
Loading