Skip to content

Commit

Permalink
deploy: 5fcf84a
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilienLC committed Nov 21, 2024
1 parent 5d1a06d commit 408d321
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Binary file modified .doctrees/environment.pickle
Binary file not shown.
Binary file modified .doctrees/index.doctree
Binary file not shown.
14 changes: 8 additions & 6 deletions _modules/cneuromax/fitting/deeplearning/utils/lightning.html
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ <h1>Source code for cneuromax.fitting.deeplearning.utils.lightning</h1><div clas
<span class="kn">from</span> <span class="nn">cneuromax.utils.beartype</span> <span class="kn">import</span> <span class="n">one_of</span>
<span class="kn">from</span> <span class="nn">cneuromax.utils.misc</span> <span class="kn">import</span> <span class="n">can_connect_to_internet</span>

<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>


<div class="viewcode-block" id="instantiate_trainer">
<a class="viewcode-back" href="../../../../../_autosummary/cneuromax.fitting.deeplearning.utils.lightning.html#cneuromax.fitting.deeplearning.utils.lightning.instantiate_trainer">[docs]</a>
Expand Down Expand Up @@ -591,7 +593,7 @@ <h1>Source code for cneuromax.fitting.deeplearning.utils.lightning</h1><div clas
<span class="n">default_root_dir</span><span class="o">=</span><span class="n">output_dir</span> <span class="o">+</span> <span class="s2">&quot;/lightning/tuner/&quot;</span><span class="p">,</span>
<span class="n">callbacks</span><span class="o">=</span><span class="p">[</span><span class="n">batch_size_finder</span><span class="p">],</span>
<span class="p">)</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Finding good `batch_size` parameter...&quot;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Finding good `batch_size` parameter...&quot;</span><span class="p">)</span>
<span class="n">per_device_batch_size</span> <span class="o">=</span> <span class="kc">None</span>
<span class="c1"># Prevents the `fit` method from raising a `KeyError`, see:</span>
<span class="c1"># https://github.com/Lightning-AI/pytorch-lightning/issues/18114</span>
Expand All @@ -609,7 +611,7 @@ <h1>Source code for cneuromax.fitting.deeplearning.utils.lightning</h1><div clas
<span class="p">)</span>
<span class="k">if</span> <span class="n">per_device_batch_size</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">per_device_batch_size</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Best `batch_size` parameter: </span><span class="si">{</span><span class="n">per_device_batch_size</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Best `batch_size` parameter: </span><span class="si">{</span><span class="n">per_device_batch_size</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">per_device_batch_size</span></div>


Expand Down Expand Up @@ -638,9 +640,9 @@ <h1>Source code for cneuromax.fitting.deeplearning.utils.lightning</h1><div clas
<span class="sd"> A roughly optimal ``per_device_num_workers`` value.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">launcher_config</span> <span class="o">=</span> <span class="n">get_launcher_config</span><span class="p">()</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Finding good `num_workers` parameter...&quot;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Finding good `num_workers` parameter...&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">launcher_config</span><span class="o">.</span><span class="n">cpus_per_task</span> <span class="ow">in</span> <span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="mi">1</span><span class="p">]:</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Only 1 worker available/provided. Returning 0.&quot;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Only 1 worker available/provided. Returning 0.&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="c1"># Static type checking purposes, already narrowed down to `int`</span>
<span class="c1"># through the `if` statement above.</span>
Expand All @@ -662,7 +664,7 @@ <h1>Source code for cneuromax.fitting.deeplearning.utils.lightning</h1><div clas
<span class="k">if</span> <span class="n">num_data_passes</span> <span class="o">==</span> <span class="n">max_num_data_passes</span><span class="p">:</span>
<span class="k">break</span>
<span class="n">times</span><span class="p">[</span><span class="n">num_workers</span><span class="p">]</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">start_time</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;num_workers: </span><span class="si">{</span><span class="n">num_workers</span><span class="si">}</span><span class="s2">, time taken: </span><span class="si">{</span><span class="n">times</span><span class="p">[</span><span class="n">num_workers</span><span class="p">]</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span>
<span class="p">)</span>
<span class="c1"># If the time taken is not decreasing, stop the search.</span>
Expand All @@ -675,7 +677,7 @@ <h1>Source code for cneuromax.fitting.deeplearning.utils.lightning</h1><div clas
<span class="p">):</span>
<span class="k">break</span>
<span class="n">best_time</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="n">times</span><span class="p">))</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Best `num_workers` parameter: </span><span class="si">{</span><span class="n">best_time</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Best `num_workers` parameter: </span><span class="si">{</span><span class="n">best_time</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">best_time</span></div>


Expand Down
8 changes: 5 additions & 3 deletions _modules/cneuromax/fitting/neuroevolution/fit.html
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ <h1>Source code for cneuromax.fitting.neuroevolution.fit</h1><div class="highlig

<span class="n">MAX_INT</span> <span class="o">=</span> <span class="mi">2</span><span class="o">**</span><span class="mi">31</span> <span class="o">-</span> <span class="mi">1</span>

<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>


<div class="viewcode-block" id="fit">
<a class="viewcode-back" href="../../../../_autosummary/cneuromax.fitting.neuroevolution.fit.html#cneuromax.fitting.neuroevolution.fit.fit">[docs]</a>
Expand Down Expand Up @@ -612,10 +614,10 @@ <h1>Source code for cneuromax.fitting.neuroevolution.fit</h1><div class="highlig
<span class="c1"># Validate path &amp; load state</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">config</span><span class="o">.</span><span class="n">output_dir</span><span class="si">}</span><span class="s2">/</span><span class="si">{</span><span class="n">gen</span><span class="si">}</span><span class="s2">/&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">path</span> <span class="o">/</span> <span class="s2">&quot;state.pkl&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">is_file</span><span class="p">():</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;No saved state found at </span><span class="si">{</span><span class="n">path</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;No saved state found at </span><span class="si">{</span><span class="n">path</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="k">continue</span>
<span class="k">if</span> <span class="p">(</span><span class="n">path</span> <span class="o">/</span> <span class="s2">&quot;evaluation.pkl&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">is_file</span><span class="p">():</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Already evaluated generation </span><span class="si">{</span><span class="n">gen</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Already evaluated generation </span><span class="si">{</span><span class="n">gen</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="k">continue</span>
<span class="k">with</span> <span class="p">(</span><span class="n">path</span> <span class="o">/</span> <span class="s2">&quot;state.pkl&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="s2">&quot;rb&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">state</span> <span class="o">=</span> <span class="n">pickle</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
Expand All @@ -639,7 +641,7 @@ <h1>Source code for cneuromax.fitting.neuroevolution.fit</h1><div class="highlig
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">pop_size</span> <span class="o">//</span> <span class="mi">2</span><span class="p">):</span>
<span class="n">agent</span><span class="p">:</span> <span class="n">BaseAgent</span> <span class="o">=</span> <span class="n">agents</span><span class="p">[</span><span class="n">selected_indices</span><span class="p">[</span><span class="n">i</span><span class="p">]][</span><span class="mi">0</span><span class="p">]</span>
<span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">num_tests</span><span class="p">):</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Test #</span><span class="si">{</span><span class="n">j</span><span class="si">}</span><span class="s2">, agent #</span><span class="si">{</span><span class="n">i</span><span class="si">}</span><span class="s2">, generation #</span><span class="si">{</span><span class="n">gen</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Test #</span><span class="si">{</span><span class="n">j</span><span class="si">}</span><span class="s2">, agent #</span><span class="si">{</span><span class="n">i</span><span class="si">}</span><span class="s2">, generation #</span><span class="si">{</span><span class="n">gen</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="n">seed_all</span><span class="p">(</span><span class="n">MAX_INT</span> <span class="o">-</span> <span class="n">j</span><span class="p">)</span>
<span class="c1"># env,fit,env+fit,env+fit+mem: reset</span>
<span class="c1"># mem,mem+fit: no reset</span>
Expand Down
6 changes: 4 additions & 2 deletions _modules/cneuromax/fitting/neuroevolution/utils/compute.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ <h1>Source code for cneuromax.fitting.neuroevolution.utils.compute</h1><div clas
<span class="kn">from</span> <span class="nn">cneuromax.utils.beartype</span> <span class="kn">import</span> <span class="n">ge</span>
<span class="kn">from</span> <span class="nn">cneuromax.utils.mpi4py</span> <span class="kn">import</span> <span class="n">get_mpi_variables</span>

<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>


<div class="viewcode-block" id="compute_generation_results">
<a class="viewcode-back" href="../../../../../_autosummary/cneuromax.fitting.neuroevolution.utils.compute.html#cneuromax.fitting.neuroevolution.utils.compute.compute_generation_results">[docs]</a>
Expand Down Expand Up @@ -595,8 +597,8 @@ <h1>Source code for cneuromax.fitting.neuroevolution.utils.compute</h1><div clas
<span class="n">elapsed_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">start_time</span>
<span class="n">fitnesses_mean</span> <span class="o">=</span> <span class="n">fitnesses</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">fitnesses_max</span> <span class="o">=</span> <span class="n">fitnesses</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">curr_gen</span><span class="si">}</span><span class="s2">: </span><span class="si">{</span><span class="n">elapsed_time</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">fitnesses_mean</span><span class="si">}</span><span class="se">\n</span><span class="si">{</span><span class="n">fitnesses_max</span><span class="si">}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">curr_gen</span><span class="si">}</span><span class="s2">: </span><span class="si">{</span><span class="n">elapsed_time</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">fitnesses_mean</span><span class="si">}</span><span class="se">\n</span><span class="si">{</span><span class="n">fitnesses_max</span><span class="si">}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">wandb</span><span class="o">.</span><span class="n">log</span><span class="p">(</span>
<span class="p">{</span>
<span class="s2">&quot;gen&quot;</span><span class="p">:</span> <span class="n">curr_gen</span><span class="p">,</span>
Expand Down

0 comments on commit 408d321

Please sign in to comment.