hugo mod vendor will write all the module dependencies to a _vendor folder, which will then be used for all subsequent builds.
You can run hugo mod vendor on any level in the module tree.
Vendoring will not store modules stored in your themes folder.
Most commands accept a --ignoreVendorPaths flag, which will then not use the vendored modules in _vendor for the module paths matching the Glob pattern given. Note that before Hugo 0.75 this flag was named --ignoreVendor and was a “all or nothing”.