# Using HF to train a custom PyTorch architecture

**URL:** <https://discuss.huggingface.co/t/using-hf-to-train-a-custom-pytorch-architecture/21008>\
**Category:** Beginners\
**Created:** [July 29, 2022, 6:22pm UTC](https://discuss.huggingface.co/t/using-hf-to-train-a-custom-pytorch-architecture/21008 "2022-07-29T18:22:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![curt-tigges](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/curt-tigges/32/5532_2.png) [@curt-tigges](https://discuss.huggingface.co/u/curt-tigges)\
**Post date:** [July 29, 2022, 6:22pm UTC](https://discuss.huggingface.co/t/using-hf-to-train-a-custom-pytorch-architecture/21008/1 "2022-07-29T18:22:57Z")

</div>

I’ve created a basic Seq2Seq transformer from scratch in PyTorch (mainly so that I can learn the architecture), and I was wondering if it is possible to train this kind of model using the HuggingFace Tokenizers, Dataset, and Trainer classes. I’d rather not hand-code the tokenization and training loop for the transformer from scratch.

Is there a way to do this with HF? Existing tutorials seem to exclusively use models that are already in the library.

If it is possible, what parts of the training would I still need to take care of (loss, masking, label smoothing, greedy decode, etc.)?
