Skip to content

Commit

Permalink
Generate Python docs from pytorch/pytorch@3fef633
Browse files Browse the repository at this point in the history
  • Loading branch information
pytorchbot committed Apr 19, 2023
1 parent 30cf152 commit 9d50996
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 119 deletions.
Binary file modified docs/main/_images/RReLU.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/main/_modules/torch.html
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,12 @@ <h1>Source code for torch</h1><div class="highlight"><pre>

<span class="k">return</span> <span class="n">compile_fx</span><span class="p">(</span><span class="n">model_</span><span class="p">,</span> <span class="n">inputs_</span><span class="p">,</span> <span class="n">config_patches</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="kn">from</span> <span class="nn">torch._inductor</span> <span class="kn">import</span> <span class="n">config</span>
<span class="k">if</span> <span class="s2">&quot;triton.cudagraphs&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span> <span class="ow">or</span> <span class="n">config</span><span class="o">.</span><span class="n">triton</span><span class="o">.</span><span class="n">cudagraphs</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;triton.cudagraphs&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">):</span>
<span class="kn">from</span> <span class="nn">torch._inductor.cudagraph_trees</span> <span class="kn">import</span> <span class="n">reset_cudagraph_trees</span>
<span class="n">reset_cudagraph_trees</span><span class="p">()</span>

<div class="viewcode-block" id="compile"><a class="viewcode-back" href="../generated/torch.compile.html#torch.compile">[docs]</a><span class="k">def</span> <span class="nf">compile</span><span class="p">(</span><span class="n">model</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Callable</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span>
<span class="n">fullgraph</span><span class="p">:</span> <span class="n">builtins</span><span class="o">.</span><span class="n">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
Expand Down
2 changes: 2 additions & 0 deletions docs/main/_modules/torch/_dynamo.html
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ <h1>Source code for torch._dynamo</h1><div class="highlight"><pre>
<span class="n">orig_code_map</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
<span class="n">guard_failures</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
<span class="n">resume_execution</span><span class="o">.</span><span class="n">ContinueExecutionCache</span><span class="o">.</span><span class="n">cache</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
<span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">eval_frame</span><span class="o">.</span><span class="n">most_recent_backend</span><span class="p">,</span> <span class="s2">&quot;reset&quot;</span><span class="p">):</span>
<span class="n">eval_frame</span><span class="o">.</span><span class="n">most_recent_backend</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
<span class="n">eval_frame</span><span class="o">.</span><span class="n">most_recent_backend</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">compilation_metrics</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
<span class="n">reset_frame_count</span><span class="p">()</span></div>
Expand Down
26 changes: 13 additions & 13 deletions docs/main/_modules/torch/_dynamo/eval_frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ <h1>Source code for torch._dynamo.eval_frame</h1><div class="highlight"><pre>
<span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

<span class="kn">from</span> <span class="nn">torch._dispatch.python</span> <span class="kn">import</span> <span class="n">enable_python_dispatcher</span>
<span class="kn">from</span> <span class="nn">torch._subclasses.fake_tensor</span> <span class="kn">import</span> <span class="n">FakeTensor</span>
<span class="kn">from</span> <span class="nn">torch.fx.experimental</span> <span class="kn">import</span> <span class="n">proxy_tensor</span>

<span class="n">always_optimize_code_objects</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">ExactWeakKeyDictionary</span><span class="p">()</span>
Expand Down Expand Up @@ -901,7 +900,7 @@ <h1>Source code for torch._dynamo.eval_frame</h1><div class="highlight"><pre>
<span class="k">elif</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span> <span class="o">&gt;=</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">11</span><span class="p">):</span>
<span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
<span class="s2">&quot;torch.compile support of Python 3.11 is experimental. &quot;</span>
<span class="s2">&quot;Program may generate incorrect results or segfault.&quot;</span>
<span class="s2">&quot;Program may segfault.&quot;</span>
<span class="p">)</span>


Expand Down Expand Up @@ -1154,7 +1153,6 @@ <h1>Source code for torch._dynamo.eval_frame</h1><div class="highlight"><pre>
<span class="n">graph</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">out_guards</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">graph_captured_input</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">example_fake_inputs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">graph_captured_result</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">,</span> <span class="o">...</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span>

<span class="k">def</span> <span class="nf">produce_matching</span><span class="p">(</span><span class="n">source_args</span><span class="p">,</span> <span class="n">candidate_args</span><span class="p">):</span>
Expand Down Expand Up @@ -1191,17 +1189,21 @@ <h1>Source code for torch._dynamo.eval_frame</h1><div class="highlight"><pre>
<span class="k">assert</span> <span class="n">out_guards</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">,</span> <span class="s2">&quot;whole graph export entails exactly one guard export&quot;</span>
<span class="n">out_guards</span> <span class="o">=</span> <span class="n">guards</span>

<span class="n">fake_mode</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">example_inputs</span> <span class="o">=</span> <span class="p">[]</span>

<span class="k">def</span> <span class="nf">dynamo_normalization_capturing_compiler</span><span class="p">(</span>
<span class="n">gm</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">fx</span><span class="o">.</span><span class="n">GraphModule</span><span class="p">,</span> <span class="n">example_inputs</span>
<span class="n">gm</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">fx</span><span class="o">.</span><span class="n">GraphModule</span><span class="p">,</span> <span class="n">inner_example_inputs</span>
<span class="p">):</span>
<span class="k">nonlocal</span> <span class="n">graph</span>
<span class="k">assert</span> <span class="p">(</span>
<span class="n">graph</span> <span class="ow">is</span> <span class="kc">None</span>
<span class="p">),</span> <span class="s2">&quot;Tried to emit a second graph during export. Tracing through &#39;f&#39; must produce a single graph.&quot;</span>
<span class="n">graph</span> <span class="o">=</span> <span class="n">gm</span>

<span class="k">nonlocal</span> <span class="n">example_fake_inputs</span>
<span class="n">example_fake_inputs</span> <span class="o">=</span> <span class="n">example_inputs</span>
<span class="k">nonlocal</span> <span class="n">fake_mode</span><span class="p">,</span> <span class="n">example_inputs</span>
<span class="n">fake_mode</span> <span class="o">=</span> <span class="n">_guards</span><span class="o">.</span><span class="n">detect_fake_mode</span><span class="p">(</span><span class="n">inner_example_inputs</span><span class="p">)</span>
<span class="n">example_inputs</span> <span class="o">=</span> <span class="n">inner_example_inputs</span>

<span class="k">def</span> <span class="nf">result_capturing_wrapper</span><span class="p">(</span><span class="o">*</span><span class="n">graph_inputs</span><span class="p">):</span>
<span class="k">nonlocal</span> <span class="n">graph_captured_result</span>
Expand Down Expand Up @@ -1238,6 +1240,7 @@ <h1>Source code for torch._dynamo.eval_frame</h1><div class="highlight"><pre>
<span class="n">graph</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
<span class="p">),</span> <span class="s2">&quot;Failed to produce a graph during tracing. Tracing through &#39;f&#39; must produce a single graph.&quot;</span>
<span class="k">assert</span> <span class="n">out_guards</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">,</span> <span class="s2">&quot;Failed to produce guards during tracing&quot;</span>
<span class="k">assert</span> <span class="n">fake_mode</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>

<span class="n">matched_input_elements_positions</span> <span class="o">=</span> <span class="n">produce_matching</span><span class="p">(</span><span class="n">flat_args</span><span class="p">,</span> <span class="n">graph_captured_input</span><span class="p">)</span>

Expand Down Expand Up @@ -1283,19 +1286,16 @@ <h1>Source code for torch._dynamo.eval_frame</h1><div class="highlight"><pre>
<span class="n">r</span><span class="o">.</span><span class="n">node</span><span class="o">.</span><span class="n">meta</span><span class="p">[</span><span class="s2">&quot;val&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_node</span><span class="o">.</span><span class="n">meta</span><span class="p">[</span><span class="s2">&quot;val&quot;</span><span class="p">]</span>
<span class="k">return</span> <span class="n">r</span>

<span class="c1"># NB: This is mostly hitting the cache; Dynamo already converted these</span>
<span class="n">example_fake_inputs</span> <span class="o">=</span> <span class="p">[</span><span class="n">fake_mode</span><span class="o">.</span><span class="n">from_tensor</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">example_inputs</span><span class="p">]</span>

<span class="k">if</span> <span class="n">aten_graph</span><span class="p">:</span>
<span class="c1"># Running graph with interpreter is needed for propagating the stack_trace</span>
<span class="k">def</span> <span class="nf">graph_with_interpreter</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">):</span>
<span class="k">with</span> <span class="n">torch</span><span class="o">.</span><span class="n">fx</span><span class="o">.</span><span class="n">traceback</span><span class="o">.</span><span class="n">preserve_node_meta</span><span class="p">():</span>
<span class="k">return</span> <span class="n">torch</span><span class="o">.</span><span class="n">fx</span><span class="o">.</span><span class="n">Interpreter</span><span class="p">(</span><span class="n">graph</span><span class="p">)</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">)</span>

<span class="n">fake_tensor_mode</span> <span class="o">=</span> <span class="n">null_context</span><span class="p">()</span>
<span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">example_fake_inputs</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">FakeTensor</span><span class="p">):</span>
<span class="n">fake_tensor_mode</span> <span class="o">=</span> <span class="n">val</span><span class="o">.</span><span class="n">fake_mode</span>
<span class="k">break</span>

<span class="k">with</span> <span class="n">enable_python_dispatcher</span><span class="p">(),</span> <span class="n">fake_tensor_mode</span><span class="p">:</span>
<span class="k">with</span> <span class="n">enable_python_dispatcher</span><span class="p">(),</span> <span class="n">fake_mode</span><span class="p">:</span>
<span class="n">graph</span> <span class="o">=</span> <span class="n">make_fx</span><span class="p">(</span>
<span class="n">graph_with_interpreter</span><span class="p">,</span>
<span class="n">decomposition_table</span><span class="o">=</span><span class="n">decomposition_table</span><span class="p">,</span>
Expand Down
7 changes: 5 additions & 2 deletions docs/main/_modules/torch/_tensor_str.html
Original file line number Diff line number Diff line change
Expand Up @@ -991,12 +991,15 @@ <h1>Source code for torch._tensor_str</h1><div class="highlight"><pre>
<span class="n">prefix</span> <span class="o">=</span> <span class="s2">&quot;_to_functional_tensor(&quot;</span>
<span class="n">tensor_str</span> <span class="o">=</span> <span class="nb">repr</span><span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">_from_functional_tensor</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_meta</span><span class="p">:</span>
<span class="c1"># Circular import problem, so we import it here</span>
<span class="kn">from</span> <span class="nn">torch._subclasses.fake_tensor</span> <span class="kn">import</span> <span class="n">FakeTensor</span>

<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_meta</span> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">FakeTensor</span><span class="p">):</span>
<span class="n">suffixes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;size=&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="nb">tuple</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">shape</span><span class="p">)))</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dtype</span> <span class="o">!=</span> <span class="n">torch</span><span class="o">.</span><span class="n">get_default_dtype</span><span class="p">():</span>
<span class="n">suffixes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;dtype=&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dtype</span><span class="p">))</span>
<span class="c1"># TODO: This implies that ellipses is valid syntax for allocating</span>
<span class="c1"># a meta tensor, which it could be, but it isn&#39;t right now</span>
<span class="c1"># a meta tensor or FakeTensor, which it could be, but it isn&#39;t right now</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">custom_contents_provided</span><span class="p">:</span>
<span class="n">tensor_str</span> <span class="o">=</span> <span class="s2">&quot;...&quot;</span>
<span class="k">else</span><span class="p">:</span>
Expand Down
Loading

0 comments on commit 9d50996

Please sign in to comment.