-
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathprofiling.html
More file actions
383 lines (351 loc) · 24.2 KB
/
profiling.html
File metadata and controls
383 lines (351 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Profiling Stan programs with CmdStanR • cmdstanr</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><!-- Bootstrap --><link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/cosmo/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="Profiling Stan programs with CmdStanR">
<meta property="og:description" content="cmdstanr">
<meta property="og:image" content="https://mc-stan.org/cmdstanr/logo.png">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body data-spy="scroll" data-target="#toc">
<div class="container template-article">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">cmdstanr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.9.0</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
<span class="fa fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="../articles/index.html">Vignettes</a>
</li>
<li>
<a href="../reference/index.html">Functions</a>
</li>
<li>
<a href="../news/index.html">News</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Other Packages
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="https://mc-stan.org/rstan" class="external-link">rstan</a>
</li>
<li>
<a href="https://mc-stan.org/rstanarm" class="external-link">rstanarm</a>
</li>
<li>
<a href="https://mc-stan.org/bayesplot" class="external-link">bayesplot</a>
</li>
<li>
<a href="https://mc-stan.org/shinystan" class="external-link">shinystan</a>
</li>
<li>
<a href="https://mc-stan.org/loo" class="external-link">loo</a>
</li>
<li>
<a href="https://mc-stan.org/projpred" class="external-link">projpred</a>
</li>
<li>
<a href="https://mc-stan.org/rstantools" class="external-link">rstantools</a>
</li>
<li>
<a href="https://mc-stan.org/posterior" class="external-link">posterior</a>
</li>
</ul>
</li>
<li>
<a href="https://mc-stan.org" class="external-link">Stan</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://twitter.com/mcmc_stan" class="external-link">
<span class="fa fa-twitter"></span>
</a>
</li>
<li>
<a href="https://github.com/stan-dev/cmdstanr" class="external-link">
<span class="fa fa-github"></span>
</a>
</li>
<li>
<a href="https://discourse.mc-stan.org/" class="external-link">
<span class="fa fa-users"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1 data-toc-skip>Profiling Stan programs with CmdStanR</h1>
<h4 data-toc-skip class="author">Rok Češnovar,
Jonah Gabry and Ben Bales</h4>
<small class="dont-index">Source: <a href="https://github.com/stan-dev/cmdstanr/blob/HEAD/vignettes/profiling.Rmd" class="external-link"><code>vignettes/profiling.Rmd</code></a></small>
<div class="hidden name"><code>profiling.Rmd</code></div>
</div>
<div class="section level3">
<h3 id="introduction">Introduction<a class="anchor" aria-label="anchor" href="#introduction"></a>
</h3>
<p>This vignette demonstrates how to use the new profiling functionality
introduced in CmdStan 2.26.0.</p>
<p>Profiling identifies which parts of a Stan program are taking the
longest time to run and is therefore a useful guide when working on
optimizing the performance of a model.</p>
<p>However, be aware that the statistical assumptions that go into a
model are the most important factors in overall model performance. It is
often not possible to make up for model problems with just brute force
computation. For ideas on how to address performance of your model from
a statistical perspective, see Gelman (2020).</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://mc-stan.org/cmdstanr/">cmdstanr</a></span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/install_cmdstan.html">check_cmdstan_toolchain</a></span><span class="op">(</span>fix <span class="op">=</span> <span class="cn">TRUE</span>, quiet <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level3">
<h3 id="adding-profiling-statements-to-a-stan-program">Adding profiling statements to a Stan program<a class="anchor" aria-label="anchor" href="#adding-profiling-statements-to-a-stan-program"></a>
</h3>
<p>Consider a simple logistic regression with parameters
<code>alpha</code> and <code>beta</code>, covariates <code>X</code>, and
outcome <code>y</code>.</p>
<pre><code>data {
int<lower=1> k;
int<lower=0> n;
matrix[n, k] X;
array[n] int y;
}
parameters {
vector[k] beta;
real alpha;
}
model {
beta ~ std_normal();
alpha ~ std_normal();
y ~ bernoulli_logit(X * beta + alpha);
}</code></pre>
<p>A simple question is how much time do the prior calculations take
compared against the likelihood? To answer this we surround the prior
and likelihood calculations with <code>profile</code> statements.</p>
<pre><code>profile("priors") {
target += std_normal_lpdf(beta);
target += std_normal_lpdf(alpha);
}
profile("likelihood") {
target += bernoulli_logit_lpmf(y | X * beta + alpha);
}</code></pre>
<p>In general we recommend using a separate <code>.stan</code> file, but
for convenience in this vignette we’ll write the Stan program as a
string and use <code><a href="../reference/write_stan_file.html">write_stan_file()</a></code> to write it to a temporary
file.</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">profiling_bernoulli_logit</span> <span class="op"><-</span> <span class="fu"><a href="../reference/write_stan_file.html">write_stan_file</a></span><span class="op">(</span><span class="st">'</span></span>
<span><span class="st">data {</span></span>
<span><span class="st"> int<lower=1> k;</span></span>
<span><span class="st"> int<lower=0> n;</span></span>
<span><span class="st"> matrix[n, k] X;</span></span>
<span><span class="st"> array[n] int y;</span></span>
<span><span class="st">}</span></span>
<span><span class="st">parameters {</span></span>
<span><span class="st"> vector[k] beta;</span></span>
<span><span class="st"> real alpha;</span></span>
<span><span class="st">}</span></span>
<span><span class="st">model {</span></span>
<span><span class="st"> profile("priors") {</span></span>
<span><span class="st"> target += std_normal_lpdf(beta);</span></span>
<span><span class="st"> target += std_normal_lpdf(alpha);</span></span>
<span><span class="st"> }</span></span>
<span><span class="st"> profile("likelihood") {</span></span>
<span><span class="st"> target += bernoulli_logit_lpmf(y | X * beta + alpha);</span></span>
<span><span class="st"> }</span></span>
<span><span class="st">}</span></span>
<span><span class="st">'</span><span class="op">)</span></span></code></pre></div>
<p>We can then run the model as usual and Stan will collect the
profiling information for any sections with <code>profile</code>
statements.</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Compile the model</span></span>
<span><span class="va">model</span> <span class="op"><-</span> <span class="fu"><a href="../reference/cmdstan_model.html">cmdstan_model</a></span><span class="op">(</span><span class="va">profiling_bernoulli_logit</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Generate some fake data</span></span>
<span><span class="va">n</span> <span class="op"><-</span> <span class="fl">1000</span></span>
<span><span class="va">k</span> <span class="op"><-</span> <span class="fl">20</span></span>
<span><span class="va">X</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/matrix.html" class="external-link">matrix</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">n</span> <span class="op">*</span> <span class="va">k</span><span class="op">)</span>, ncol <span class="op">=</span> <span class="va">k</span><span class="op">)</span></span>
<span></span>
<span><span class="va">y</span> <span class="op"><-</span> <span class="fl">3</span> <span class="op">*</span> <span class="va">X</span><span class="op">[</span>,<span class="fl">1</span><span class="op">]</span> <span class="op">-</span> <span class="fl">2</span> <span class="op">*</span> <span class="va">X</span><span class="op">[</span>,<span class="fl">2</span><span class="op">]</span> <span class="op">+</span> <span class="fl">1</span></span>
<span><span class="va">p</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/stats/Uniform.html" class="external-link">runif</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span></span>
<span><span class="va">y</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html" class="external-link">ifelse</a></span><span class="op">(</span><span class="va">p</span> <span class="op"><</span> <span class="op">(</span><span class="fl">1</span> <span class="op">/</span> <span class="op">(</span><span class="fl">1</span> <span class="op">+</span> <span class="fu"><a href="https://rdrr.io/r/base/Log.html" class="external-link">exp</a></span><span class="op">(</span><span class="op">-</span><span class="va">y</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>, <span class="fl">1</span>, <span class="fl">0</span><span class="op">)</span></span>
<span><span class="va">stan_data</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span>k <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/nrow.html" class="external-link">ncol</a></span><span class="op">(</span><span class="va">X</span><span class="op">)</span>, n <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/nrow.html" class="external-link">nrow</a></span><span class="op">(</span><span class="va">X</span><span class="op">)</span>, y <span class="op">=</span> <span class="va">y</span>, X <span class="op">=</span> <span class="va">X</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Run one chain of the model</span></span>
<span><span class="va">fit</span> <span class="op"><-</span> <span class="va">model</span><span class="op">$</span><span class="fu">sample</span><span class="op">(</span>data <span class="op">=</span> <span class="va">stan_data</span>, chains <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level3">
<h3 id="accessing-the-profiling-information-from-r">Accessing the profiling information from R<a class="anchor" aria-label="anchor" href="#accessing-the-profiling-information-from-r"></a>
</h3>
<p>The raw profiling information can then be accessed with the
<code>$profiles()</code> method, which returns a list containing one
data frame per chain (profiles across multiple chains are not
automatically aggregated). Details on the column names are available in
the <a href="https://mc-stan.org/docs/2_26/cmdstan-guide/stan-csv.html#profiling-csv-output-file" class="external-link">CmdStan
documentation</a>.</p>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">fit</span><span class="op">$</span><span class="fu">profiles</span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<pre><code>[[1]]
name thread_id total_time forward_time reverse_time chain_stack
1 likelihood 0x7ff85af4eb00 0.60053000 0.49063200 0.10989800 52272
2 priors 0x7ff85af4eb00 0.00611123 0.00426232 0.00184891 34848
no_chain_stack autodiff_calls no_autodiff_calls
1 34865424 17424 1
2 34848 17424 1</code></pre>
<p>The <code>total_time</code> column is the total time spent inside a
given profile statement. It is clear that the vast majority of time is
spent in the likelihood function.</p>
</div>
<div class="section level3">
<h3 id="comparing-to-a-faster-version-of-the-model">Comparing to a faster version of the model<a class="anchor" aria-label="anchor" href="#comparing-to-a-faster-version-of-the-model"></a>
</h3>
<p>Stan’s specialized glm functions can be used to make models like this
faster. In this case the likelihood can be replaced with</p>
<pre><code>target += bernoulli_logit_glm_lpmf(y | X, alpha, beta);</code></pre>
<p>We’ll keep the same <code><a href="https://rdrr.io/r/stats/profile.html" class="external-link">profile()</a></code> statements so that the
profiling information for the new model is collected automatically just
like for the previous one.</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">profiling_bernoulli_logit_glm</span> <span class="op"><-</span> <span class="fu"><a href="../reference/write_stan_file.html">write_stan_file</a></span><span class="op">(</span><span class="st">'</span></span>
<span><span class="st">data {</span></span>
<span><span class="st"> int<lower=1> k;</span></span>
<span><span class="st"> int<lower=0> n;</span></span>
<span><span class="st"> matrix[n, k] X;</span></span>
<span><span class="st"> array[n] int y;</span></span>
<span><span class="st">}</span></span>
<span><span class="st">parameters {</span></span>
<span><span class="st"> vector[k] beta;</span></span>
<span><span class="st"> real alpha;</span></span>
<span><span class="st">}</span></span>
<span><span class="st">model {</span></span>
<span><span class="st"> profile("priors") {</span></span>
<span><span class="st"> target += std_normal_lpdf(beta);</span></span>
<span><span class="st"> target += std_normal_lpdf(alpha);</span></span>
<span><span class="st"> }</span></span>
<span><span class="st"> profile("likelihood") {</span></span>
<span><span class="st"> target += bernoulli_logit_glm_lpmf(y | X, alpha, beta);</span></span>
<span><span class="st"> }</span></span>
<span><span class="st">}</span></span>
<span><span class="st">'</span><span class="op">)</span></span></code></pre></div>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">model_glm</span> <span class="op"><-</span> <span class="fu"><a href="../reference/cmdstan_model.html">cmdstan_model</a></span><span class="op">(</span><span class="va">profiling_bernoulli_logit_glm</span><span class="op">)</span></span>
<span><span class="va">fit_glm</span> <span class="op"><-</span> <span class="va">model_glm</span><span class="op">$</span><span class="fu">sample</span><span class="op">(</span>data <span class="op">=</span> <span class="va">stan_data</span>, chains <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span></code></pre></div>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">fit_glm</span><span class="op">$</span><span class="fu">profiles</span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<pre><code>[[1]]
name thread_id total_time forward_time reverse_time chain_stack
1 likelihood 0x7ff85af4eb00 0.30010000 0.29864700 0.00145329 51729
2 priors 0x7ff85af4eb00 0.00520466 0.00393537 0.00126928 34486
no_chain_stack autodiff_calls no_autodiff_calls
1 17243 17243 1
2 34486 17243 1</code></pre>
<p>We can see from the <code>total_time</code> column that this is much
faster than the previous model.</p>
</div>
<div class="section level3">
<h3 id="per-gradient-timings-and-memory-usage">Per-gradient timings, and memory usage<a class="anchor" aria-label="anchor" href="#per-gradient-timings-and-memory-usage"></a>
</h3>
<p>The other columns of the profiling output are documented in the <a href="https://mc-stan.org/docs/2_26/cmdstan-guide/stan-csv.html#profiling-csv-output-file" class="external-link">CmdStan
documentation</a>.</p>
<p>The timing numbers are broken down by forward pass and reverse pass,
and the <code>chain_stack</code> and <code>no_chain_stack</code> columns
contain information about how many autodiff variables were saved in the
process of performing a calculation.</p>
<p>These numbers are all totals – times are the total times over the
whole calculation, and <code>chain_stack</code> counts are similarly the
total counts of autodiff variables used over the whole calculation. It
is often convenient to have per-gradient calculations (which will be
more stable across runs with different seeds). To compute these, use the
<code>autodiff_calls</code> column.</p>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">profile_chain_1</span> <span class="op"><-</span> <span class="va">fit</span><span class="op">$</span><span class="fu">profiles</span><span class="op">(</span><span class="op">)</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span></span>
<span><span class="va">per_gradient_timing</span> <span class="op"><-</span> <span class="va">profile_chain_1</span><span class="op">$</span><span class="va">total_time</span><span class="op">/</span><span class="va">profile_chain_1</span><span class="op">$</span><span class="va">autodiff_calls</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">per_gradient_timing</span><span class="op">)</span> <span class="co"># two elements for the two profile statements in the model</span></span></code></pre></div>
<pre><code>[1] 3.446568e-05 3.507363e-07</code></pre>
</div>
<div class="section level3">
<h3 id="accessing-and-saving-the-profile-files">Accessing and saving the profile files<a class="anchor" aria-label="anchor" href="#accessing-and-saving-the-profile-files"></a>
</h3>
<p>After sampling (or optimization or variational inference) finishes,
CmdStan stores the profiling data in CSV files in a temporary location.
The paths of the profiling CSV files can be retrieved using
<code>$profile_files()</code>.</p>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">fit</span><span class="op">$</span><span class="fu">profile_files</span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<pre><code>[1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2a6FE1/model_6580008f67848265f3dfd0e7ae3b0600-profile-202503310851-1-810271.csv"</code></pre>
<p>These can be saved to a more permanent location with the
<code>$save_profile_files()</code> method.</p>
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># see ?save_profile_files for info on optional arguments</span></span>
<span><span class="va">fit</span><span class="op">$</span><span class="fu">save_profile_files</span><span class="op">(</span>dir <span class="op">=</span> <span class="st">"path/to/directory"</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="references">References<a class="anchor" aria-label="anchor" href="#references"></a>
</h2>
<p>Gelman, Andrew, Aki Vehtari, Daniel Simpson, Charles C. Margossian,
Bob Carpenter, Yuling Yao, Lauren Kennedy, Jonah Gabry, Paul-Christian
Bürkner, and Martin Modrák. 2020. “Bayesian Workflow.” <a href="https://arxiv.org/abs/2011.01808" class="external-link uri">https://arxiv.org/abs/2011.01808</a>.</p>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
<nav id="toc" data-toggle="toc"><h2 data-toc-skip>Contents</h2>
</nav>
</div>
</div>
<footer><div class="copyright">
<p></p>
<p>Developed by Jonah Gabry, Rok Češnovar, Andrew Johnson, Steve Bronder.</p>
</div>
<div class="pkgdown">
<p></p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.9.</p>
</div>
</footer>
</div>
</body>
</html>