1# ExecuTorch API Life Cycle and Deprecation Policy 2 3## API Life Cycle 4 5 6 7Each API of ExecuTorch falls into one of the following life cycle states: 8 9_Experimental_ 10 11- APIs in this stage are under active development and may change or be removed 12 at any time. That said, the expectation is that we will eventually promote it 13 to _Stable_, unless sufficient negative signals have been collected from the 14 community or better alternatives have been found. 15- _Experimental_ APIs will be clearly marked (see the “How to Mark API State” 16 section below). 17- _Experimental_ APIs may be changed or removed without notice, and developers 18 should expect no stability guarantees. 19 20_Stable_ 21 22- APIs are considered to be _Stable_ if they are not marked as _Experimental_ or 23 _Deprecated._ 24- APIs in this stage have been thoroughly tested and are considered ready for 25 production use. 26- The recommended best practice is to not deprecate stable APIs. When writing an 27 API, write it in such a way that it doesn’t need to be deprecated in the 28 future. 29- _Stable_ APIs can be changed, but not in a breaking way. If breaking changes 30 have to be made, _Stable_ APIs will always transition to _Deprecated_ before 31 being broken/removed from the library. 32 33_Deprecated_ 34 35- APIs in this stage are no longer recommended for use and will be removed in a 36 future version of ExecuTorch. 37- _Deprecated_ APIs will be clearly marked (see the “How to Mark API State” 38 section below). 39- _Deprecated_ APIs will remain functional for at least the _deprecation period_ 40 (see the “Deprecation Period” section below) to allow developers time to 41 migrate to alternative APIs. 42 43_Deleted_ 44 45- APIs whose removal are made permanent. Cleaned up from both code and 46 documentation. 47 48## Deprecation Policy 49 50Follow these steps to deprecate and remove an API: 51 521. Discuss the change and collect initial feedback. 532. Clearly mark the API deprecated in code and documentation (See “How to Mark 54 API State” below). 553. Listen to user feedback after the first release that deprecates the API. 56 Users who weren't involved in the original discussion may have good arguments 57 for not deprecating or removing the API. 584. Once the deprecation period has passed, the API may be removed (See 59 “Deprecation Period” below). Be sure to also remove references from the 60 documentation. 61 62 63We also use deprecation as a way to make breaking changes to an existing 64interface: for example, if adding a non-optional parameter to a method. To do 65this without breaking existing users: 66 671. In a single commit: 68 - Create a new API that meets the new requirements. 69 - Deprecate the old API and recommend that users move to the new API. 702. Migrate use cases from the old API to the new API. 713. Delete the old API after the deprecation period. 72 73## How to Mark API State 74 75When possible, the ExecuTorch code uses language-standard ways to annotate API 76lifecycle state in the code. This makes it easier for IDEs and other tools to 77communicate state to developers. 78 79<table> 80 <tr> 81 <td><strong>Language</strong> 82 </td> 83 <td><strong>Code</strong> 84 </td> 85 <td><strong>Documentation</strong> 86 </td> 87 </tr> 88 <tr> 89 <td>Python 90 </td> 91 <td> 92 93Use the 94<a href="https://github.com/pytorch/executorch/blob/main/exir/_warnings.py">executorch.exir._warnings.deprecated</a> 95decorator. 96 97<p> 98Use the 99<a href="https://github.com/pytorch/executorch/blob/main/exir/_warnings.py">executorch.exir._warnings.experimental</a> 100decorator. 101 102 </td> 103 <td> 104 105Use <code>.. warning::</code> in the docstrings of deprecated and experimental 106APIs. See 107<a href="https://github.com/pytorch/pytorch/blob/cd8bbdc71a0258292381a7d54c8b353988d02ff4/torch/nn/utils/stateless.py#L170">example 108usage</a>. 109 110</ul> 111 </td> 112 </tr> 113 <tr> 114 <td>C++ 115 </td> 116 <td> 117 118Use the <code>ET_DEPRECATED</code> annotation macro. See <a href="https://github.com/pytorch/executorch/blob/8e0f856ee269b319ac4195509cf31e3f548aa0e8/runtime/executor/program.h#L81">example usage</a>. 119 120<p> 121<p> 122Use the <code>ET_EXPERIMENTAL</code> annotation macro. 123</ul> 124 </td> 125 <td> 126 127Start Doxygen comments with <code>DEPRECATED:</code> See 128<a href="https://github.com/pytorch/executorch/blob/9d859653ae916d0a72f6b2b5c5925bed38832140/runtime/executor/program.h#L139">example 129usage</a>. 130 131<p> 132<p> 133Start Doxygen comments with <code>EXPERIMENTAL:</code>. 134 </td> 135 </tr> 136 <tr> 137 <td>Java 138 </td> 139 <td> 140 141Use <a href="https://docs.oracle.com/javase/9/docs/api/java/lang/Deprecated.html">java.lang.Deprecated</a>. 142 143<p> 144<p> 145 146Use <a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:docs/api_guidelines/annotations.md">androidx.annotation.RequiresOptIn</a>. 147 148 </td> 149 <td> 150<p> 151<pre><code>/** 152* @deprecated Use {@link #newMethod()} instead. 153*/ 154</code></pre> 155<p> 156<pre><code>/** 157* Warning: This API is experimental. 158*/</code></pre> 159 </td> 160 </tr> 161 <tr> 162 <td>Objective-C 163 </td> 164 <td> 165<p> 166<code>__attribute__((deprecated("Use newMethod instead")));</code> 167<p> 168<p> 169<code>__attribute__((deprecated("This API is experimental and may change without notice.")));</code> 170 </td> 171 <td> 172<p> 173<pre><code> 174/** 175* @deprecated Use `newMethod` instead. 176*/ 177</code></pre> 178<p> 179<pre><code> 180/** 181* @experimental This API is experimental. 182*/</code></pre> 183<p> 184 </td> 185 </tr> 186 <tr> 187 <td>Swift 188 </td> 189 <td> 190<p> 191<code>@available(*, deprecated, message: "Use newMethod instead")</code> 192<p> 193<p> 194<code>@available(*, message: "This API is experimental")</code> 195 </td> 196 <td> 197<p> 198<code>/// - Warning: Deprecated. Use `newMethod()` instead.</code> 199<p> 200<code>/// - Warning: This API is experimental.</code> 201 </td> 202 </tr> 203</table> 204 205The annotations would trigger static and/or runtime warning that contains at 206least these information: 207 2081. Clearly point to the non-deprecated alternative to migrate to, or be clear if 209 there is no alternative; 2102. Specify the earliest version in which the API may actually be removed (See 211 “Deprecation Period” below). 212 213## Deprecation Period 214 215Here we recommend waiting for at least 2 minor releases before the removal. For 216example, if a function is marked as _deprecated_ in release 1.3.x, then it can 217be _deleted_ in 1.5.x or later. 218