[ ](https://pytorch.org)

  * [ Get Started ](/get-started)
  * Ecosystem 

[ PyTorch Conference - 2024  September 18-19 in San Francisco
](https://events.linuxfoundation.org/pytorch-conference/) [ Tools  Learn about
the tools and frameworks in the PyTorch Ecosystem  ](/ecosystem)

  * Edge 

[ About PyTorch Edge  ](/edge) [ ExecuTorch  ](/executorch-overview)

  * [ Blog ](/blog)
  * [ Tutorials ](https://pytorch.org/tutorials)
  * Docs 

[ PyTorch  ](/docs) [ torchaudio  ](/audio) [ torchtext  ](/text) [
torchvision  ](/vision) [ torcharrow  ](/torcharrow) [ TorchData  ](/data) [
TorchRec  ](/torchrec) [ TorchServe  ](/serve) [ PyTorch on XLA Devices
](/xla/release/1.6/index.html)

  * Resources 

[ About  Learn about PyTorch’s features and capabilities  ](/features) [
PyTorch Foundation  Learn more about the PyTorch Foundation.  ](/foundation) [
Community  Join the PyTorch developer community to contribute, learn, and get
your questions answered.  ](/#community-module) [ Community stories  Learn how
our community solves real, everyday machine learning problems with PyTorch
](/community-stories) [ Developer Resources  Find resources and get questions
answered  ](/resources) [ Events  Find events, webinars, and podcasts
](/events) [ Forums  A place to discuss PyTorch code, issues, install,
research  ](https://discuss.pytorch.org) [ Models (Beta)  Discover, publish,
and reuse pre-trained models  ](/hub)

  * [ GitHub ](https://github.com/pytorch/pytorch)
  * X 

#  End-to-end  
Machine Learning  
Framework

PyTorch enables fast, flexible experimentation and efficient production
through a user-friendly front-end, distributed training, and ecosystem of
tools and libraries.

[ Get Started ](/get-started)

    
    
      import torch
      class MyModule(torch.nn.Module):
    
        def __init__(self, N, M):
          super(MyModule, self).__init__()
          self.weight = torch.nn.Parameter(torch.rand(N, M))
    
        def forward(self, input):
          if input.sum() > 0:
            output = self.weight.mv(input)
          else:
            output = self.weight + input
          return output
    
        # Compile the model code to a static representation
        my_script_module = torch.jit.script(MyModule(3, 4))
    
        # Save the compiled code and model data so it can be loaded elsewhere
        my_script_module.save("my_script_module.pt")
    

###  Production Ready

With TorchScript, PyTorch provides ease-of-use and flexibility in eager mode,
while seamlessly transitioning to graph mode for speed, optimization, and
functionality in C++ runtime environments.

###  TorchServe

TorchServe is an easy to use tool for deploying PyTorch models at scale. It is
cloud and environment agnostic and supports features such as multi-model
serving, logging, metrics and the creation of RESTful endpoints for
application integration.

    
    
      ## Convert the model from PyTorch to TorchServe format
      torch-model-archiver --model-name densenet161 \
      --version 1.0 --model-file serve/examples/image_classifier/densenet_161/model.py \
      --serialized-file densenet161-8d451a50.pth \
      --extra-files serve/examples/image_classifier/index_to_name.json \
      --handler image_classifier
    
      ## Host your PyTorch model
    
     torchserve --start --model-store model_store --models densenet161=densenet161.mar
    
    
    
      import torch.distributed as dist
      from torch.nn.parallel import DistributedDataParallel
      
      dist.init_process_group(backend='gloo')
      model = DistributedDataParallel(model)
    

###  Distributed Training

Optimize performance in both research and production by taking advantage of
native support for asynchronous execution of collective operations and peer-
to-peer communication that is accessible from Python and C++.

###  Mobile (Experimental)

PyTorch supports an end-to-end workflow from Python to deployment on iOS and
Android. It extends the PyTorch API to cover com