dedupe primary_modules to avoid deduping in chunking, reduce memory usage (#7510)
### Description
This allows to avoid a clone into an IndexSet in
`graph_node_to_referenced_nodes`, so improves performance and avoids
temporary memory consumption.
### Testing Instructions
<!--
Give a quick description of steps to test your changes.
-->
Closes PACK-2586