Python utilities used by Deep Procedural Intelligence
Project description
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
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
ChunkWriter
provides a convenient API for writing output in multiple parts (chunks).RichPath
an API that abstract local and Azure Blob paths in your code.*Iterator
Wrappers that can parallelize and shuffle iterators.{load,save}_json[l]_gz
convenience API for loading and writing.json[l].gz
files.git_tag_run
tags the current working directory git the state of the code.run_and_debug
when an exception happens, start a debug session. Usually a wrapper of__main__
.
General Machine Learning Utilities dpu_utils.mlutils
Vocabulary
map 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.BpeVocabulary
a vocabulary for machine learning models that employs BPE (viasentencepiece
).CharTensorizer
convert 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
,CSharpLattice
represent lattices and useful operations on lattices in Python.get_language_keywords()
an API to retrieve the keyword tokens for many programming languages.deduplication.DuplicateDetector
API to detects (near)duplicates in codebases. See also here for a command line tool.
TensorFlow 1.x Utilities dpu_utils.tfutils
get_activation
retrieve activations function by name.GradRatioLoggingOptimizer
a wrapper around optimizers that logs the ratios of grad norms to parameter norms.TFVariableSaver
save 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_name
retrieve activation functions by name.gelu
The GeLU activation function.MLP
An MLP layer.
Unsorted segment operations following TensorFlow's unsorted_segment_sum
operations:
TensorFlow Models dpu_utils.tfmodels
SparseGGNN
a sparse GGNN implementation.AsyncGGNN
an asynchronous GGNN implementation.
These models have not been tested with TF 2.0.
PyTorch Utilities dpu_utils.ptutils
BaseComponent
a wrapper abstract class aroundnn.Module
that takes care of essential elements of most neural network components.ComponentTrainer
a training loop forBaseComponent
s.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dpu_utils-0.2.8.tar.gz
.
File metadata
- Download URL: dpu_utils-0.2.8.tar.gz
- Upload date:
- Size: 45.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ef0fa5683f6e81a3cb60871d15732cbf186537ba7a9cac04570d7dea6777ce3 |
|
MD5 | ac3b885a47ad73d149e07c2630e86016 |
|
BLAKE2b-256 | 4149e0ad55d85bbe4fb798467c541e954e5778195d42350bfd751769ef280c5c |
File details
Details for the file dpu_utils-0.2.8-py2.py3-none-any.whl
.
File metadata
- Download URL: dpu_utils-0.2.8-py2.py3-none-any.whl
- Upload date:
- Size: 63.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8888e05c0502ab231768d6b1c5e58f0122a9c0bce3e8e76061cce5d0436f45e |
|
MD5 | d82b6b1a225e1197d4e3d51801721d99 |
|
BLAKE2b-256 | cbc30be07ed9bb958d49fe489ab451b0f826b53288083479296029e8322dcf29 |