8000 Add flag for disabling flash attention by Maxusmusti · Pull Request #15 · instructlab/training · GitHub
[go: up one dir, main page]

Skip to content
Closed
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
19 changes: 11 additions & 8 deletions main_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,23 @@ def setup_model(args, tokenizer, train_loader, grad_accum):
bnb_4bit_compute_dtype=torch.float16, # if not set will throw a warning about slow speeds when training
)

base_model_args = {
"pretrained_model_name_or_path": args.model_name_or_path,
"torch_dtype": torch.bfloat16,
"quantization_config": bnb_config,
}
if not args.disable_flash_attn:
base_model_args["attn_implementation"] = "flash_attention_2"

if args.is_granite:
from dolomite_engine.hf_models.models import GPTDolomiteForCausalLM
model = GPTDolomiteForCausalLM.from_pretrained(
args.model_name_or_path,
attn_implementation="flash_attention_2",
torch_dtype=torch.bfloat16,
**base_model_args,
use_padding_free_transformer=True,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if you want to disable FA2, you also need to disable padding free, since it uses FA2 under the hood

quantization_config=bnb_config,
)
else:
model = AutoModelForCausalLM.from_pretrained(
args.model_name_or_path,
attn_implementation="flash_attention_2",
torch_dtype=torch.bfloat16,
quantization_config=bnb_config,
**base_model_args
)

if len(tokenizer) > model.config.vocab_size:
Expand Down Expand Up @@ -426,6 +428,7 @@ def main(args):
parser.add_argument("--lora_quant_bits", type=int, default=None)
parser.add_argument("--lora_target_modules", nargs='+', default=None)
parser.add_argument("--max_batch_len", type=int, default=60000)
parser.add_argument("--disable_flash_attn", action="store_true")
args = parser.parse_args()
set_random_seed(args.seed)
main(args)
Expand Down
0