The accepted answer gets the model loaded in FP16. One detail worth adding for anyone trying this on a T4: when the OOM happens tells you what to change.
dtype=torch.float16 in current Transformers versions (torch_dtype=torch.float16 in older versions). If FP16 still leaves too little room on the T4, 4-bit loading with bitsandbytes gives you more headroom. LlamaForCausalLM, keep max_new_tokens low for the first test too. The KV cache grows as the sequence gets longer, so a model that loads successfully can still run out of memory during generation. That’s why lowering the batch size helped in the FAIR example. It reduces memory used during inference. Loading in FP16 reduces the memory needed for the weights.