# Pytorch equivalant of tensorflow GradientTape

Hi,

I was wondering what the equivlent in pytorch of the following tensor flow is:

``````def compute_apply_gradients(model, x, optimizer):
loss = compute_loss(model, x)
``````

many thanks,

chaslie

Hi,

You can look at the tutorials on the website. But that would be something like:

``````loss = compute_loss(model, x)
{"ft_lang_label":"__label__en","ft_lang_prob":0.5257118,"math_prob":0.85835814,"size":343,"snap":"2022-05-2022-21","text_gpt3_token_len":76,"char_repetition_ratio":0.15044248,"word_repetition_ratio":0.0,"special_character_ratio":0.20408164,"punctuation_ratio":0.2542373,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9973007,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-20T08:42:45Z\",\"WARC-Record-ID\":\"<urn:uuid:dd95a30e-669c-4383-8d35-10537379c133>\",\"Content-Length\":\"16853\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3390774e-a205-4d85-a367-ddf4601df51a>\",\"WARC-Concurrent-To\":\"<urn:uuid:78d70092-fd87-4ec3-8595-e92222b3ea47>\",\"WARC-IP-Address\":\"159.203.145.104\",\"WARC-Target-URI\":\"https://discuss.pytorch.org/t/pytorch-equivalant-of-tensorflow-gradienttape/74915\",\"WARC-Payload-Digest\":\"sha1:HXAVDTPXVX7DFU3ASKJDWY6RAGYGMHQM\",\"WARC-Block-Digest\":\"sha1:VBKZM45UYFDWOGVKGWEFUM5L5RENWOFD\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662531762.30_warc_CC-MAIN-20220520061824-20220520091824-00673.warc.gz\"}"}