std::cerr << "API was used: " << event_name << std::endl;
    });
    

Note for developers: new API trigger points can be added in code with `
C10_LOG_API_USAGE_ONCE("my_api")  ` in C++ or `
torch._C._log_api_usage_once("my.api")  ` in Python.

##  Attaching metadata to saved TorchScript models  ¶

TorchScript modules can be saved as an archive file that bundles serialized
parameters and module code as TorchScript (see [ ` torch.jit.save()  `
](../generated/torch.jit.save.html#torch.jit.save "torch.jit.save") ). It’s
often convenient to bundle additional information together with the model, for
example, description of model producer or auxiliary artifacts.

It can be achieved by passing the ` _extra_files  ` argument to [ `
torch.jit.save()  ` ](../generated/torch.jit.save.html#torch.jit.save
"torch.jit.save") and ` torch::jit::load  ` to store and retrieve arbitrary
binary blobs during saving process. Since TorchScript files are regular ZIP
archives, extra information gets stored as regular files inside archive’s `
extra/  ` directory.

There’s also a global hook allowing to attach extra files to any TorchScript
archive produced in the current process. It might be useful to tag models with
producer metadata, akin to JPEG metadata produced by digital cameras. Example
usage might look like:

    
    
    SetExportModuleExtraFilesHook([](const Module&) {
        ExtraFilesMap files;
        files["producer_info.json"] = "{\"user\": \"" + getenv("USER") + "\"}";
        return files;
    });
    

##  Build environment considerations  ¶

TorchScript’s compilation needs to have access to the original python files as
it uses python’s ` inspect.getsource  ` call. In certain production
environments it might require explicitly deploying ` .py  ` files along with
precompiled ` .pyc  ` .

##  Common extension points  ¶

PyTorch APIs are generally loosely coupled and it’s easy to replace a
component with specialized version. Common extension points include:

  * Custom operators implemented in C++ - see [ tutorial for more details ](https://pytorch.org/tutorials/advanced/cpp_extension.html) . 

  * Custom data reading can be often integrated directly by invoking corresponding python library. Existing functionality of [ ` torch.utils.data  ` ](../data.html#module-torch.utils.data "torch.utils.data") can be utilized by extending [ ` Dataset  ` ](../data.html#torch.utils.data.Dataset "torch.utils.data.Dataset") or [ ` IterableDataset  ` ](../data.html#torch.utils.data.IterableDataset "torch.utils.data.IterableDataset") . 

[ Next ![](../_static/images/chevron-right-orange.svg) ](multiprocessing.html
"Multiprocessing best practices") [ ![](../_static/images/chevron-right-
orange.svg) Previous ](faq.html "Frequently Asked Questions")

* * *

© 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) .

  * Features for large-scale deployments 
    * Fleet-wide operator profiling 
    * API usage logging 
    * Attaching metadata to saved TorchScript models 
    * Build environment considerations 
    * Common extension points 

![](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.