In trying to use mcbackend to store sample from big model, I seem to have run into exactly the issue I’m trying to solve, namely memory problems with the full trace. @michaelosthege is this something you have encountered before? Key parts of the model and the error message are below. Thanks much! (ping @AlexAndorra)
ch_client = clickhouse_driver.Client("localhost")
ch_backend = mcbackend.ClickHouseBackend(ch_client)
with pm.Model(coords=COORDS) as model_x:
...
with model_x:
pm.sample(1000,trace=ch_backend)
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Dimensionality of sample stat 'sampler_0__warning' is undefined. Assuming ndim=0.
Dimensionality of sample stat 'sampler_0__warning' is undefined. Assuming ndim=0.
Dimensionality of sample stat 'sampler_0__warning' is undefined. Assuming ndim=0.
Dimensionality of sample stat 'sampler_0__warning' is undefined. Assuming ndim=0.
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [PsppIdent_odds, latent_log_species_landings_, species_sigma_year, TaxonAGG_odds_, taxon_sigma_year, intercept, importer_species_effect, dyad_effect, trade_effect, sd_intercept_sd, lsd_intercept, sd_unreliability_sd, lsd_unreliability_effect]
Traceback (most recent call last):██████████████████████████████████████████████████████████| 100.00% [8000/8000 1:42:43<00:00 Sampling 4 chains, 0 divergences]
File "/Users/aaronmacneil/Dropbox/My Mac (Mac-mini.local)/Documents/GitHub/Global_Shark_Meat/notebooks/Joint_Trade_Landings_Model.py", line 364, in <module>
pm.sample(1000,trace=ch_backend)
File "/Users/aaronmacneil/mambaforge/envs/gsm-project/lib/python3.11/site-packages/pymc/sampling/mcmc.py", line 827, in sample
return _sample_return(
^^^^^^^^^^^^^^^
File "/Users/aaronmacneil/mambaforge/envs/gsm-project/lib/python3.11/site-packages/pymc/sampling/mcmc.py", line 861, in _sample_return
mtrace = MultiTrace(traces)[:length]
~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "/Users/aaronmacneil/mambaforge/envs/gsm-project/lib/python3.11/site-packages/pymc/backends/base.py", line 370, in __getitem__
return self._slice(idx)
^^^^^^^^^^^^^^^^
File "/Users/aaronmacneil/mambaforge/envs/gsm-project/lib/python3.11/site-packages/pymc/backends/base.py", line 537, in _slice
new_traces = [trace._slice(slice) for trace in self._straces.values()]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/aaronmacneil/mambaforge/envs/gsm-project/lib/python3.11/site-packages/pymc/backends/base.py", line 537, in <listcomp>
new_traces = [trace._slice(slice) for trace in self._straces.values()]
^^^^^^^^^^^^^^^^^^^
File "/Users/aaronmacneil/mambaforge/envs/gsm-project/lib/python3.11/site-packages/pymc/backends/mcbackend.py", line 194, in _slice
draw = self._chain.get_draws_at(i, var_names=vnames)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/aaronmacneil/Dropbox/My Mac (Mac-mini.local)/Documents/GitHub/mcbackend-0.5.2/mcbackend/backends/clickhouse.py", line 291, in get_draws_at
return self._get_row_at(idx, var_names)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/aaronmacneil/Dropbox/My Mac (Mac-mini.local)/Documents/GitHub/mcbackend-0.5.2/mcbackend/backends/clickhouse.py", line 236, in _get_row_at
data = self._client.execute(query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/aaronmacneil/mambaforge/envs/gsm-project/lib/python3.11/site-packages/clickhouse_driver/client.py", line 373, in execute
rv = self.process_ordinary_query(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/aaronmacneil/mambaforge/envs/gsm-project/lib/python3.11/site-packages/clickhouse_driver/client.py", line 571, in process_ordinary_query
return self.receive_result(with_column_types=with_column_types,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/aaronmacneil/mambaforge/envs/gsm-project/lib/python3.11/site-packages/clickhouse_driver/client.py", line 204, in receive_result
return result.get_result()
^^^^^^^^^^^^^^^^^^^
File "/Users/aaronmacneil/mambaforge/envs/gsm-project/lib/python3.11/site-packages/clickhouse_driver/result.py", line 50, in get_result
for packet in self.packet_generator:
File "/Users/aaronmacneil/mambaforge/envs/gsm-project/lib/python3.11/site-packages/clickhouse_driver/client.py", line 220, in packet_generator
packet = self.receive_packet()
^^^^^^^^^^^^^^^^^^^^^
File "/Users/aaronmacneil/mambaforge/envs/gsm-project/lib/python3.11/site-packages/clickhouse_driver/client.py", line 237, in receive_packet
raise packet.exception
clickhouse_driver.errors.ServerException: Code: 241.
DB::Exception: Memory limit (total) exceeded: would use 64.98 GiB (attempt to allocate chunk of 34359869503 bytes), maximum: 57.60 GiB. OvercommitTracker decision: Query was selected to stop by OvercommitTracker.: while reading column export_proportion at ./store/9e5/9e596fd0-8db6-499c-ba4d-219fa128a121/: While executing Log. Stack trace:
<Empty trace>