Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishivi committed Sep 15, 2023
1 parent 9c6a7a6 commit 68d5e1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions eval/alpaca_farm_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
parser.add_argument("--openai_engine", "-o", type=str, default=None)
# where to save generations - default current directory
parser.add_argument("--save_folder", "-s", type=str, default="")
parser.add_argument("--tokenizer", "-t", type=str, default=None)
parser.add_argument("--padding_side", "-p", type=str, default="right") # llama2 requires left padding
args = parser.parse_args()

assert not (args.model and args.openai_engine), "only provide one of --model or --openai"
Expand All @@ -35,19 +37,23 @@
my_outputs = []
if not os.path.exists(os.path.join(args.save_folder, sample_filename)):
if args.openai_engine is None:
model = AutoModelForCausalLM.from_pretrained(args.model, device_map="auto", torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained(args.model)
model = AutoModelForCausalLM.from_pretrained(
args.model,
device_map="auto",
torch_dtype=torch.bfloat16,)
tokenizer = AutoTokenizer.from_pretrained(args.model if args.tokenizer is None else args.tokenizer, legacy=True, use_fast=False)
# add padding token if not already there
if tokenizer.pad_token is None:
tokenizer.add_special_tokens({"pad_token": "<pad>"})
model.resize_token_embeddings(len(tokenizer))
tokenizer.padding_side = args.padding_side
logging.info("model and data loaded!")
logging.info("generating...")
generation_config = GenerationConfig.from_pretrained(
args.model,
max_new_tokens=2048,
# top_p=0.9,
# do_sample=True,
# do_sample=False,
# num_return_sequences=1,
# temperature=1.0,
# top_k=0
Expand Down
6 changes: 3 additions & 3 deletions open_instruct/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,15 @@ def main():
# We keep track of the loss at each logged step
total_loss += loss.detach().float()
accelerator.backward(loss)
# clip gradient norm. don't do this with deepspeed
if accelerator.sync_gradients and args.clip_grad_norm > 0:
accelerator.clip_grad_norm_(model.parameters(), args.clip_grad_norm)
optimizer.step()
optimizer.zero_grad()
lr_scheduler.step()

# Checks if the accelerator has performed an optimization step behind the scenes
if accelerator.sync_gradients:
# if set, clip the gradient norm. Don't do this with deepspeed.
if args.clip_grad_norm > 0:
accelerator.clip_grad_norm_(model.parameters(), args.clip_grad_norm)
progress_bar.update(1)
completed_steps += 1
if args.logging_steps and completed_steps % args.logging_steps == 0:
Expand Down

0 comments on commit 68d5e1d

Please sign in to comment.