h a model in various segments and checkpoint each
segment. All segments except the last will run in [ ` torch.no_grad()  `
](generated/torch.no_grad.html#torch.no_grad "torch.no_grad") manner, i.e.,
not storing the intermediate activations. The inputs of each checkpointed
segment will be saved for re-running the segment in the backward pass.

See  ` checkpoint()  ` on how checkpointing works.

Warning

Checkpointing doesn’t work with [ ` torch.autograd.grad()  `
](autograd.html#torch.autograd.grad "torch.autograd.grad") , but only with [ `
torch.autograd.backward()  ` ](autograd.html#torch.autograd.backward
"torch.autograd.backward") .

Parameters

    

  * **functions** – A [ ` torch.nn.Sequential  ` ](generated/torch.nn.Sequential.html#torch.nn.Sequential "torch.nn.Sequential") or the list of modules or functions (comprising the model) to run sequentially. 

  * **segments** – Number of chunks to create in the model 

  * **input** – A Tensor that is input to ` functions  `

  * **preserve_rng_state** ( [ _bool_ ](https://docs.python.org/3/library/functions.html#bool "\(in Python v3.8\)") _,_ _optional_ _,_ _default=True_ ) – Omit stashing and restoring the RNG state during each checkpoint. 

Returns

    

Output of running ` functions  ` sequentially on ` *inputs  `

Example

    
    
    >>> model = nn.Sequential(...)
    >>> input_var = checkpoint_sequential(model, chunks, input_var)
    

[ Next ![](_static/images/chevron-right-orange.svg) ](cpp_extension.html
"torch.utils.cpp_extension") [ ![](_static/images/chevron-right-orange.svg)
Previous ](bottleneck.html "torch.utils.bottleneck")

* * *

© Copyright 2019, Torch Contributors.

Built with [ Sphinx ](http://sphinx-doc.org/) using a [ theme
](https://github.com/rtfd/sphinx_rtd_theme) provided by [ Read the Docs
](https://readthedocs.org) .

  * torch.utils.checkpoint 

![](https://www.googleadservices.com/pagead/conversion/795629140/?label=txkmCPmdtosBENSssfsC&guid=ON&script=0)

##  Docs

Access comprehensive developer documentation for PyTorch

[ View Docs ](https://pytorch.org/docs/stable/index.html)

##  Tutorials

Get in-depth tutorials for beginners and advanced developers

[ View Tutorials ](https://pytorch.org/tutorials)

##  Resources

Find development resources and get your questions answered

[ View Resources ](https://pytorch.org/resources)

[ ](https://pytorch.org/)

  * [ PyTorch ](https://pytorch.org/)
  * [ Get Started ](https://pytorch.org/get-started)
  * [ Features ](https://pytorch.org/features)
  * [ Ecosystem ](https://pytorch.org/ecosystem)
  * [ Blog ](https://pytorch.org/blog/)
  * [ Contributing ](https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md)

  * [ Resources ](https://pytorch.org/resources)
  * [ Tutorials ](https://pytorch.org/tutorials)
  * [ Docs ](https://pytorch.org/docs/stable/index.html)
  * [ Discuss ](https://discuss.pytorch.org)
  * [ Github Issues ](https://github.com/pytorch/pytorch/issues)
  * [ Brand Guidelines ](https://pytorch.org/assets/brand-guidelines/PyTorch-Brand-Guidelines.pdf)

  * Stay Connected 
  * Email Address 

[ ](https://www.facebook.com/pytorch) [ ](https://twitter.com/pytorch) [
](https://www.youtube.com/pytorch)

To analyze traffic and optimize your experience, we serve cookies on this
site. By clicking or navigating, you agree to allow our usage of cookies. As
the current maintainers of this site, Facebook’s Cookies Policy applies. Learn
more, including about available controls: [ Cookies Policy
](https://www.facebook.com/policies/cookies/) .

![](_static/images/pytorch-x.svg)

[ ](https://pytorch.org/)

  * [ Get Started ](https://pytorch.org/get-started)
  * [ Features ](https://pytorch.org/features)
  * [ Ecosystem ](https://pytorch.org/ecosystem)
  * [ Mobile ](https://pytorch.org/mobile)
  * [ PyTorch Hub ](https://pytorch.org/hub)
  * [ Blog ](https://pytorch.org/blog/)
  * [ Tutorials ](https://pytorch.org/tutorials)
  * [ Docs ](https://pytorch.org/docs/stable/index.html)
  * [ R