Package: dpu-utils
DPU UtilitiesThis contains a set of utilities used across projects of theDPU team.PythonStored in thepythonsubdirectory, published as thedpu-utilspackage.Installationpipinstalldpu-utilsOR via the community-maintained Conda recipe:condainstall-cconda-forgedpu-utilsOverviewBelow you can find an overview of the utilities included. Detailed documentation
is provided at the docstring of each class.Generic Utilitiesdpu_utils.utilsChunkWriterprovides 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 Utilitiesdpu_utils.mlutilsVocabularymap 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 Utilitiesdpu_utils.codeutilssplit_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 alsoherefor a command line tool.treesitter.parser_forgetTree-sitterparser by language name.TensorFlow 1.x Utilitiesdpu_utils.tfutilsget_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'sunsorted_segment_sumoperations:unsorted_segment_logsumexpunsorted_segment_log_softmaxunsorted_segment_softmaxTensorFlow 2.x Utilitiesdpu_utils.tf2utilsget_activation_function_by_nameretrieve activation functions by name.geluThe GeLU activation function.MLPAn MLP layer.Unsorted segment operations following TensorFlow'sunsorted_segment_sumoperations:unsorted_segment_logsumexpunsorted_segment_log_softmaxunsorted_segment_softmaxTensorFlow Modelsdpu_utils.tfmodelsSparseGGNNa sparse GGNN implementation.AsyncGGNNan asynchronous GGNN implementation.These models have not been tested with TF 2.0.PyTorch Utilitiesdpu_utils.ptutilsBaseComponenta wrapper abstract class aroundnn.Modulethat
takes care of essential elements of most neural network components.ComponentTrainera training loop forBaseComponents.Command-line toolsApproximate Duplicate Code DetectionYou can use thededuplicationclicommand to detect duplicates in pre-processed source code, by invokingdeduplicationcliDATA_PATHOUT_JSONwhereDATA_PATHis a file containing tokenized.jsonl.gzfiles andOUT_JSONis the target output file.
For more options look at--help.An exact (but usually slower) version of this can be foundherealong with code to tokenize Java, C#, Python and JavaScript into the relevant formats.TestsRun the unit testspythonsetup.pytestGenerate code coverage reports# pip install coveragecoveragerun--sourcedpu_utils/setup.pytest&&\coveragehtmlThe resulting HTML file will be inhtmlcov/index.html..NETStored in thedotnetsubdirectory.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.ContributingThis 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, visithttps://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 theMicrosoft Open Source Code of Conduct.
For more information see theCode of Conduct FAQor
contactopencode@microsoft.comwith any additional questions or comments.