Fix tensor device mismatch and improve dataset module usability#4
Merged
Conversation
- Add `dataset` to packages in `pyproject.toml` and create `dataset/__init__.py` so it can be installed and imported globally. - Update `dataset/lenet_cifar.py` and `dataset/cnn_exp.py` to use dynamic absolute paths (via `__file__`) for the `_data` directory and `.pth` weight files instead of hardcoded relative paths. - Add `os.path.expanduser` to `dataset/imagenet.py` to properly resolve paths containing the `~` shortcut.
…igTree YAML files - Update `MRFI.__init__` to properly attach sub-modules when reading configuration from a raw string/YAML file format (`ConfigTree`). - Merge the user-provided YAML configuration with a complete empty configuration tree dynamically generated from the model structue. This prevents `AttributeError` for missing `FI_config` keys during forward passes and weight fetching when using incomplete YAML configuration files.
Owner
|
Thank you very much. I'll read this later. |
Owner
|
Nice pull request. This will be more convenient. There are small issues. Tensor device operation error_idx = error_list.to(weight.device) cause test failing. Maybe if isinstance(error_list, torch.Tensor):
error_list= error_list.to(weight.device)will pass.
If you later pass test by |
…Updated examples and readme to suit the changes
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request focuses on improving data path handling, file saving/loading robustness, device compatibility, and configuration merging across the codebase. The main themes are: (1) making data and model file paths more robust and portable, (2) ensuring tensor indexing is device-aware, and (3) enhancing configuration merging logic.
Data and Model Path Handling Improvements:
cnn_exp.pyandlenet_cifar.pyto dynamically determine the dataset directory using either theDATASETSenvironment variable or a path relative to the script, improving portability and flexibility. [1] [2]cnn_exp.pyandlenet_cifar.pyto use absolute paths based on the script's directory, ensuring consistency regardless of the working directory. [1] [2] [3]datasetto the list of packages inpyproject.tomlto ensure it is included during packaging and installation.imagenet.py, expanded the user path in the default testset folder location to support~for the home directory.Device-Aware Tensor Indexing:
mrfi.py, ensured that index tensors (error_list) used for activation and weight fault injection are moved to the same device as the target tensors, preventing device mismatch errors during tensor operations. [1] [2] [3] [4]Configuration Merging Enhancement:
MRFIclass by merging user-provided configuration dictionaries into a default configuration tree, allowing for more flexible and robust configuration overrides.