This project has been archived by its maintainers, and is no longer receiving any updates.
DPU Utilities 

This contains a set of utilities used across projects of the DPU team.
Python
Stored in the python subdirectory, published as the dpu-utils package.
Installation
pip install dpu-utils
OR via the community-maintained Conda recipe:
conda install -c conda-forge dpu-utils
Overview
Below you can find an overview of the utilities included. Detailed documentation is provided at the docstring of each class.
Generic Utilities dpu_utils.utils
ChunkWriterprovides a convenient API for writing output in multiple parts (chunks).RichPathan API that abstract local and Azure Blob paths in your code.*IteratorWrappers that can parallelize and shuffle iterators.{load,save}_json[l]_gzconvenience API for loading and writing.json[l].gzfiles.git_tag_runtags the current working directory git the state of the code.run_and_debugwhen an exception happens, start a debug session. Usually a wrapper of__main__.
General Machine Learning Utilities dpu_utils.mlutils
Vocabularymap elements into unique integer ids and back. Commonly used in machine learning models that work over discrete data (e.g. words in NLP). Contains methods for converting an list of tokens into their "tensorized" for of integer ids.BpeVocabularya vocabulary for machine learning models that employs BPE (viasentencepiece).CharTensorizerconvert character sequences into into tensors, commonly used in machine learning models whose input is a list of characters.
Code-related Utilities dpu_utils.codeutils
split_identifier_into_parts()split identifiers into subtokens on CamelCase and snake_case.Lattice,CSharpLatticerepresent lattices and useful operations on lattices in Python.get_language_keywords()an API to retrieve the keyword tokens for many programming languages.language_candidates_from_suffix()a function to retrieve the candidate language given the file suffix.deduplication.DuplicateDetectorAPI to detects (near)duplicates in codebases. See also here for a command line tool.treesitter.parser_forget Tree-sitter parser by language name.
TensorFlow 1.x Utilities dpu_utils.tfutils
get_activationretrieve activations function by name.GradRatioLoggingOptimizera wrapper around optimizers that logs the ratios of grad norms to parameter norms.TFVariableSaversave TF variables in an object that can be pickled.
Unsorted segment operations following TensorFlow's unsorted_segment_sum operations:
TensorFlow 2.x Utilities dpu_utils.tf2utils
get_activation_function_by_nameretrieve activation functions by name.geluThe GeLU activation function.MLPAn MLP layer.
Unsorted segment operations following TensorFlow's unsorted_segment_sum operations:
TensorFlow Models dpu_utils.tfmodels
SparseGGNNa sparse GGNN implementation.AsyncGGNNan asynchronous GGNN implementation.
These models have not been tested with TF 2.0.
PyTorch Utilities dpu_utils.ptutils
BaseComponenta wrapper abstract class aroundnn.Modulethat takes care of essential elements of most neural network components.ComponentTrainera training loop forBaseComponents.
Command-line tools
Approximate Duplicate Code Detection
You can use the deduplicationcli command to detect duplicates in pre-processed source code, by invoking
deduplicationcli DATA_PATH OUT_JSON
where DATA_PATH is a file containing tokenized .jsonl.gz files and OUT_JSON is the target output file.
For more options look at --help.
An exact (but usually slower) version of this can be found here along with code to tokenize Java, C#, Python and JavaScript into the relevant formats.
Tests
Run the unit tests
python setup.py test
Generate code coverage reports
# pip install coverage
coverage run --source dpu_utils/ setup.py test && \
coverage html
The resulting HTML file will be in htmlcov/index.html.
.NET
Stored in the dotnet subdirectory.
Generic Utilities:
Microsoft.Research.DPU.Utils.RichPath: a convenient way of using both paths and Azure paths in your code.
Code-related Utilities:
Microsoft.Research.DPU.CSharpSourceGraphExtraction: infrastructure to extract Program Graphs from C# projects.
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Metadata
Release files for dpu-utils 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dpu_utils-0.6.1.tar.gz | 55.6 kB | Without provenance | Details for dpu_utils-0.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dpu_utils-0.6.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for dpu_utils-0.6.1-py2.py3-none-any.whl |
Total release size: 128.9 kB
Release files / dpu_utils-0.6.1.tar.gz
| Download URL | dpu_utils-0.6.1.tar.gz |
|---|---|
| Size | 55.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31b1a4e82f3f0b5c6df00f2968667e8846f1bac74d0947cfd3afdb5bcd0ab73c
|
|
BLAKE2b-256 checksum How to use checksums |
1d6b0507dd6dbf64d015e67d27b6191cd1239c89639efeca8165099ac39d4450
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9
|
Release files / dpu_utils-0.6.1-py2.py3-none-any.whl
| Download URL | dpu_utils-0.6.1-py2.py3-none-any.whl |
|---|---|
| Size | 73.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
65c592a53b3d2aa2b92210b757bb3e5a18c308bb6e93063166cc6a39558a3643
|
|
BLAKE2b-256 checksum How to use checksums |
963ce17829798697d4d1070ece078e00dc633728423f0d3687d1cdf950a961bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9
|
Security for dpu-utils 0.6.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.