shenweichen / shenweichen/DeepCTR-Torch
a question about whether self.feature_index is in CPU or GPU
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.5k
- Forks
- 733
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I am relatively new to Pytorch. I have a question regarding the data in CPU/GPU, for example, in the source code here
In particular,
sparse_embedding_list = [embedding_dict[feat.embedding_name](
X[:, self.feature_index[feat.name][0]:self.feature_index[feat.name][1]].long()) for
feat in sparse_feature_columns]
It is pretty clear that X is the minibatch tensor data that has already been moved to GPU. embedding_dict is a Moduledict and feature_index is a plain Python Ordereddict. I had a few basic reading, it sounds like a dictionary object cannot directly be migrated into GPU, but only each tensor for each key can be copied one by one. So I am not sure for example, in the constructor init() of the BaseModel, what self.to(device) is going to do for its dictionary object?
That comes to my more specific question here, I am wondering when calling to build sparse_embedding_list, how Pytorch handles this, is everything here already in GPU when calling init() or some runtime copy of the value self.feature_index[feat.name] into GPU, does it incur any efficiency issue?
Thank you for your help!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with deepctr_torch/models/basemodel.py at the linked BaseModel constructor and the sparse_embedding_list expression. Read how self.to(device) is applied and compare the ModuleDict with the plain feature_index mapping. Done means documenting which values move to the device, which remain Python objects, and whether this path adds runtime copying.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100