You should use BartForConditionalGeneration, since this model adds a language modeling head on top of BartModel. BartModel itself is just the encoder-decoder Transformer, without any head on top. The language modeling head on top is necessary, in order to decode the hidden states to actual predicted tokens, and to generate text.
Yes, check out my notebook here: https://github.com/NielsRogge/Transformers-Tutorials/tree/master/T5 12. You just need to use BartForConditionalGeneration instead of T5ForConditionalGeneration (T5 and BART are actually very similar). Also, you can check out the improved documentation I wrote for T5 5 to illustrate how these models work, both for training and inference.
The loss gets automatically calculated for you when you provide labels to the model. It’s standard cross entropy loss between the predictions of the model and the labels.