Closed i-am-sijia closed 5 months ago
Note that when dropping columns in pandas df, the memory actually goes up momentarily before it goes down. see discussion here https://github.com/pandas-dev/pandas/issues/17092, this issue was "closed" but it did not get resolved.
Looking at my code changes last week, I realized I was also dropping the columns a bit too late for interaction simulate models. The columns should be dropped before interaction df is created. I then made those changes.
Below shows the 1-zone benchmarking runs with main branch (top) and with this PR (bottom). In the non-sharrow mode, the peak memory went down from 352 GB to 261 GB, a 25% reduction.
Component-wise memory reduction, sorted by memory saving:
I'm still dealing with some crashes in the sharrow mode.
this issue was "closed" but it did not get resolved
If you read the thread closely, you'll note that that "this is not going to be solved in pandas 1." The behind-the-curtain memory management of pandas 1.x doesn't offer any way to drop unused columns without consuming extra RAM. This is alleviated by moving to pandas 2... after the transition, there are now ways to get the memory benefit. This is (part of) the reason I've worked this past week to try to get us pandas-2 compatible.
I have some updates for the Sharrow runs. Below are three 1-zone benchmarking runs with Sharrow. The one on the top (3/20) used the main
branch at 6d817be, the middle (3/28) and bottom (3/29) ones both used this PR with the latest code changes I made last week. There is a lot to discuss here.
The peak memory of the entire model did not reduce much after dropping unused variables, although there were reductions in most components. With the main
branch, the memory peak was Mandatory Tour Scheduling (156 GB), and a close runner-up was Write Trip Matrices (155 GB). After dropping unused variables, Mandatory Tour Scheduling reduced to 101 GB, but Write Trip Matrices reduced to 147 GB. So the peak memory usage only reduced from 156 GB to 147 GB.
The two runs after dropping unused variables showed different memory usage patterns, even though they used the same source code. The one on 3/28 showed accumulation of memory in Trip Destination, while the one on 3/29 showed accumulation of memory in Mandatory Tour Scheduling (that caused School Escorting having a high mark to start with). This looks relevant to issue https://github.com/ActivitySim/activitysim/issues/816. We have "memory leaks" that seem to show up sometimes but not all times.
The total run time of the 3/28 and 3/29 runs are longer than the 3/20 run, 16.2 hours vs 13.4 hours. This could mean that dropping unused variables might have caused longer run time, even though I did not observe longer run time in the Non Sharrow runs reported week. In the Non Sharrow runs, in addition to a 25% peak memory reduction, dropping unused variable also reduced run time by 10 mins. One possibility is that dropping variables in the Sharrow mode has implications on run time that I have not realized. Another possibility is that the machine needs a reboot as things piled up that slowed it down (although this is a virtual machine with nothing else running).
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
Event | WSP Sharrow On 3-20 Main | WSP Sharrow On 3-28 PR 833 | WSP Sharrow On 3-29 PR 833 -- | -- | -- | -- Max Memory (GB) | 156.1 | 146.8 | 150.5 mandatory_tour_scheduling | 156.1 | 101.8 | 109.9 write_trip_matrices | 155.0 | 146.7 | 147.2 trip_destination | 132.8 | 146.8 | 130.4 school_escorting | 124.8 | 114.3 | 150.5 non_mandatory_tour_scheduling | 116.6 | 106.7 | 88.6 atwork_subtour_scheduling | 89.3 | 43.1 | 42.0 workplace_location | 82.8 | 72.9 | 81.2 atwork_subtour_mode_choice | 79.6 | 40.3 | 37.9 trip_mode_choice | 66.6 | 60.2 | 61.0 stop_frequency | 64.2 | 62.2 | 65.1 non_mandatory_tour_destination | 61.7 | 67.9 | 64.8 vehicle_allocation | 60.1 | 99.1 | 88.2 write_data_dictionary | 59.7 | 48.3 | 48.5 trip_scheduling | 58.9 | 50.3 | 50.7 school_location | 58.9 | 57.9 | 63.6 trip_purpose_and_destination | 55.7 | 50.7 | 48.3 atwork_subtour_destination | 54.3 | 51.0 | 48.0 track_skim_usage | 53.2 | 41.5 | 41.8 write_tables | 52.3 | 43.6 | 44.0 finalizing | 48.6 | 41.4 | 41.7 tour_mode_choice_simulate | 47.9 | 52.9 | 45.4 joint_tour_destination | 47.2 | 48.0 | 49.8 non_mandatory_tour_frequency | 42.5 | 50.7 | 41.7 trip_purpose | 39.4 | 38.1 | 38.4 joint_tour_scheduling | 36.5 | 36.0 | 33.0 atwork_subtour_frequency | 30.8 | 30.2 | 29.3 vehicle_type_choice | 28.8 | 28.7 | 27.6 joint_tour_participation | 28.8 | 29.9 | 28.5 cdap_simulate | 24.8 | 24.0 | 25.5 joint_tour_frequency | 24.2 | 24.3 | 24.4 free_parking | 21.6 | 23.3 | 23.5 joint_tour_composition | 21.3 | 21.2 | 21.2 compute_disaggregate_accessibility | 20.7 | 23.1 | 21.2 initialize_households | 20.4 | 21.2 | 22.3 mandatory_tour_frequency | 18.5 | 23.0 | 23.7 compute_accessibility | 12.7 | 15.5 | 16.9 auto_ownership_simulate | 11.1 | 12.0 | 11.8 initialize_landuse | 7.1 | 14.0 | 11.4 initialize_proto_population | 6.4 | 6.4 | 6.4 input_checker | 1.9 | 1.6 | 1.6 preload_injectables | 0.3 | 0.3 | 0.3 na | 0.3 | 0.3 | 0.3
This PR addresses https://github.com/ActivitySim/activitysim/issues/792