Skip to main content

dora-transformers

A Dora node that provides access to Hugging Face transformer models for efficient text generation and chat completion.

Features

  • Multi-platform GPU acceleration support (CUDA, CPU, MPS)
  • Memory-efficient model loading with 8-bit quantization
  • Seamless integration with speech-to-text and text-to-speech pipelines
  • Configurable system prompts and activation words
  • Support for various transformer models
  • Conversation history management
  • Optimized for both small and large language models

Getting Started

Installation

uv venv -p 3.11 --seed
uv pip install -e .

Usage

Configure the node in your dataflow YAML file:

- id: dora-transformers
  build: pip install -e path/to/dora-transformers
  path: dora-transformers
  inputs:
    text: source_node/text  # Input text to generate response for
  outputs:
    - text  # Generated response text
  env:
    MODEL_NAME: "Qwen/Qwen2.5-0.5B-Instruct"  # Model from Hugging Face
    SYSTEM_PROMPT: "You're a very succinct AI assistant with short answers."
    ACTIVATION_WORDS: "what how who where you"
    MAX_TOKENS: "128"  # Reduced for concise responses
    DEVICE: "cuda"  # Use "cpu" for CPU, "cuda" for NVIDIA GPU, "mps" for Apple Silicon
    ENABLE_MEMORY_EFFICIENT: "true"  # Enable 8-bit quantization and memory optimizations
    TORCH_DTYPE: "float16"  # Use half precision for better memory efficiency

Configuration Options

  • MODEL_NAME: Hugging Face model identifier (default: "Qwen/Qwen2.5-0.5B-Instruct")
  • SYSTEM_PROMPT: Customize the AI assistant's personality/behavior
  • ACTIVATION_WORDS: Space-separated list of words that trigger model response
  • MAX_TOKENS: Maximum number of tokens to generate (default: 128)
  • DEVICE: Computation device to use (default: "cpu")
  • ENABLE_MEMORY_EFFICIENT: Enable memory optimizations (default: "true")
  • TORCH_DTYPE: Model precision type (default: "auto")

Memory Management

The node includes several memory optimization features:

  • 8-bit quantization for CUDA devices
  • Automatic CUDA cache clearing
  • Memory-efficient model loading
  • Half-precision support

Example: Voice Assistant Pipeline

Create a conversational AI pipeline that:

  1. Captures audio from microphone
  2. Converts speech to text
  3. Generates AI responses using transformers
  4. Converts responses back to speech
nodes:
  - id: dora-microphone
    build: pip install -e ../../node-hub/dora-microphone
    path: dora-microphone
    inputs:
      tick: dora/timer/millis/2000
    outputs:
      - audio

  - id: dora-vad
    build: pip install -e ../../node-hub/dora-vad
    path: dora-vad
    inputs:
      audio: dora-microphone/audio
    outputs:
      - audio
      - timestamp_start

  - id: dora-distil-whisper
    build: pip install -e ../../node-hub/dora-distil-whisper
    path: dora-distil-whisper
    inputs:
      input: dora-vad/audio
    outputs:
      - text
    env:
      TARGET_LANGUAGE: english

  - id: dora-transformers
    build: pip install -e ../../node-hub/dora-transformers
    path: dora-transformers
    inputs:
      text: dora-distil-whisper/text
    outputs:
      - text
    env:
      MODEL_NAME: "Qwen/Qwen2.5-0.5B-Instruct"
      SYSTEM_PROMPT: "You are an AI assistant that gives extremely concise responses, never more than one or two sentences. Always be direct and to the point."
      ACTIVATION_WORDS: "what how who where you"
      MAX_TOKENS: "128"
      DEVICE: "cuda"
      ENABLE_MEMORY_EFFICIENT: "true"
      TORCH_DTYPE: "float16"

  - id: dora-kokoro-tts
    build: pip install -e ../../node-hub/dora-kokoro-tts
    path: dora-kokoro-tts
    inputs:
      text: dora-transformers/text
    outputs:
      - audio

Running the Example

dora build test.yml
dora run test.yml

Troubleshooting

If you encounter CUDA out of memory errors:

  1. Set DEVICE: "cpu" for CPU-only inference
  2. Enable memory optimizations with ENABLE_MEMORY_EFFICIENT: "true"
  3. Use a smaller model or reduce MAX_TOKENS
  4. Set TORCH_DTYPE: "float16" for reduced memory usage

Contribution Guide

Format with ruff:

uv pip install ruff
uv run ruff check . --fix

Lint with ruff:

uv run ruff check .

Test with pytest:

uv pip install pytest
uv run pytest . # Test

License

dora-transformers is released under the MIT License

Metadata

Release files for dora-transformers 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dora-transformers 1.0.0
File Size Uploaded Provenance Actions
dora_transformers-1.0.0.tar.gz 4.9 kB Without provenance Details for dora_transformers-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dora-transformers 1.0.0
File Interpreter ABI Platform Actions
dora_transformers-1.0.0-py3-none-any.whl Python 3 none any Details for dora_transformers-1.0.0-py3-none-any.whl

Total release size: 10.2 kB

Release files / dora_transformers-1.0.0.tar.gz

Download URL dora_transformers-1.0.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0d0a1d5a7e60d224a3058fcaa77a423f3c91f83d43e0dcac6b1afe65b422018c
BLAKE2b-256 checksum
How to use checksums
de990c51c20f56681693824631a63db9e67ae4c8a8792296f6ce7582ebc346fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.12

Release files / dora_transformers-1.0.0-py3-none-any.whl

Download URL dora_transformers-1.0.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ca19a0071755a57956e67df06f7a91df463b995cc73fccd92b9632fa19472ff
BLAKE2b-256 checksum
How to use checksums
3c505a51abf4c9f99f4f0026564a7f52091a64c80118bf2ee14e7099317df02e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.12

Security for dora-transformers 1.0.0

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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page