traceAI-transformers 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,87 @@
1
+ *.py[cod]
2
+
3
+ # C extensions
4
+ *.so
5
+
6
+ # IDEs
7
+ .idea/
8
+ .vscode/
9
+
10
+ # Packages
11
+ *.egg
12
+ *.egg-info
13
+ .eggs/
14
+ # build
15
+ parts
16
+ bin
17
+ var
18
+ sdist
19
+ dist
20
+ develop-eggs
21
+ .installed.cfg
22
+ lib
23
+ lib64
24
+
25
+ # Installer logs
26
+ pip-log.txt
27
+
28
+ # Unit test / coverage reports
29
+ .coverage
30
+ .tox
31
+ nosetests.xml
32
+
33
+ # Complexity
34
+ output/*.html
35
+ output/*/index.html
36
+
37
+ # Sphinx
38
+ docs/_build
39
+
40
+ # Cookiecutter
41
+ output/
42
+
43
+ .workon
44
+
45
+ **.wav
46
+ **.joblib
47
+
48
+ **/__pycache__
49
+
50
+ #Excel files
51
+ *.xlsx
52
+ #csv files
53
+ *.csv
54
+ #virtual environments
55
+ **/.venv
56
+ **/env
57
+ **/.env
58
+ *.DS_Store
59
+ *.pdf
60
+ **/node_modules
61
+ **/dist
62
+ *.log
63
+ .DS_Store
64
+ **/package-lock.json
65
+ # Standalone npm example (outside the pnpm workspace): its lockfile pins the tested dependency set.
66
+ !typescript/examples/tanstack-ai/package-lock.json
67
+ **/tsconfig.tsbuildinfo
68
+ **/.fi
69
+ **/.pytest_cache
70
+ planning/
71
+
72
+ # Java build artifacts
73
+ **/target/
74
+ **/.settings/
75
+ **/.project
76
+ **/.classpath
77
+ **/.factorypath
78
+ *.class
79
+ *.jar
80
+ *.war
81
+
82
+ # C# build artifacts
83
+ **/bin/
84
+ **/obj/
85
+
86
+ # Python
87
+ **/uv.lock
@@ -0,0 +1,103 @@
1
+ Metadata-Version: 2.5
2
+ Name: traceAI-transformers
3
+ Version: 0.1.0
4
+ Summary: OpenTelemetry instrumentation for local Hugging Face Transformers pipelines
5
+ Project-URL: Repository, https://github.com/future-agi/traceAI/tree/dev/python/frameworks/transformers
6
+ Project-URL: Documentation, https://docs.futureagi.com/docs/tracing
7
+ Author-email: Future AGI <no-reply@futureagi.com>
8
+ License-Expression: Apache-2.0
9
+ Requires-Python: <3.14,>=3.10
10
+ Requires-Dist: fi-instrumentation-otel<2,>=1.2.2
11
+ Requires-Dist: opentelemetry-instrumentation<1,>=0.50b0
12
+ Requires-Dist: transformers<6,>=4.42
13
+ Requires-Dist: wrapt<2,>=1.15
14
+ Provides-Extra: dev
15
+ Requires-Dist: mypy<2,>=1.15; extra == 'dev'
16
+ Requires-Dist: pytest<9,>=8; extra == 'dev'
17
+ Requires-Dist: torch<3,>=2.6; extra == 'dev'
18
+ Requires-Dist: traceai-huggingface>=0.1.0; extra == 'dev'
19
+ Description-Content-Type: text/markdown
20
+
21
+ # traceAI Transformers
22
+
23
+ Trace local Hugging Face Transformers pipeline inference in Future AGI. For remote Hugging Face InferenceClient calls, use `traceAI-huggingface` instead; the two instrumentors can run together.
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pip install traceAI-transformers torch
29
+ ```
30
+
31
+ Python 3.10–3.13 and Transformers 4.42–5.x are supported. Transformers 5 requires Python 3.11 or later. Use PyTorch pipelines; select the appropriate PyTorch build for your CPU or GPU.
32
+
33
+ ## Trace inference
34
+
35
+ Set `FI_API_KEY` and `FI_SECRET_KEY` in your environment, then configure tracing before calling your pipeline:
36
+
37
+ ```python
38
+ import os
39
+ from fi_instrumentation import register
40
+ from fi_instrumentation.fi_types import ProjectType
41
+ from traceai_transformers import TransformersInstrumentor
42
+ from transformers import pipeline
43
+
44
+ provider = register(
45
+ project_name="local-transformers",
46
+ project_type=ProjectType.OBSERVE,
47
+ headers={
48
+ "FI_API_KEY": os.environ["FI_API_KEY"],
49
+ "FI_SECRET_KEY": os.environ["FI_SECRET_KEY"],
50
+ },
51
+ verbose=False,
52
+ )
53
+ TransformersInstrumentor().instrument(tracer_provider=provider)
54
+
55
+ generate = pipeline(
56
+ "text-generation",
57
+ model="HuggingFaceTB/SmolLM2-135M-Instruct",
58
+ device=-1,
59
+ )
60
+ result = generate(
61
+ [{"role": "user", "content": "Explain what a tokenizer does in one sentence."}],
62
+ max_new_tokens=32,
63
+ do_sample=False,
64
+ )
65
+ print(result[0]["generated_text"][-1]["content"])
66
+ provider.force_flush()
67
+ provider.shutdown()
68
+ ```
69
+
70
+ The first run downloads the model. `register` exports OTLP traces to `https://api.futureagi.com/tracer/v1/traces` with `FI_API_KEY` and `FI_SECRET_KEY` headers. This is a traces-only endpoint, not a destination for OTLP metrics or logs. Open the `local-transformers` project in Future AGI to inspect `transformers.text-generation` spans.
71
+
72
+ ## Content and privacy
73
+
74
+ By default, only task, model architecture, timing, status and error information are recorded. Model paths, generation parameters, embedding vectors and token usage estimates are not collected.
75
+
76
+ To include bounded input/output previews:
77
+
78
+ ```python
79
+ from fi_instrumentation import TraceConfig
80
+
81
+ TransformersInstrumentor().instrument(
82
+ tracer_provider=provider,
83
+ capture_content=True,
84
+ config=TraceConfig(hide_error_details=True),
85
+ )
86
+ ```
87
+
88
+ Choose this configuration on your first `instrument()` call, or call `uninstrument()` before changing it. Previews are limited to 4,096 characters and may be truncated. `TraceConfig` input/output privacy flags override content capture. Hiding inputs also suppresses output previews, because pipeline responses can contain the original prompt or conversation. Set `FI_HIDE_ERROR_DETAILS=true` to omit exception messages, stack traces and error descriptions. Error details can contain inputs even when content capture is off.
89
+
90
+ ## Supported calls
91
+
92
+ | Pipeline | Span kind | Versions |
93
+ | --- | --- | --- |
94
+ | Text generation, including chat, batches and streamers | LLM | 4.42–5.x |
95
+ | Feature extraction, including tensor results | EMBEDDING | 4.42–5.x |
96
+ | Text-to-text generation, summarization and translation | LLM | 4.x only |
97
+ | Extractive question answering | CHAIN | 4.x only |
98
+
99
+ Transformers 5 removed the historical text-to-text, summarization, translation and extractive question-answering pipelines. Use a text-generation chat model on 5.x. Direct `model.generate()` calls, other tasks, TensorFlow pipelines, and model loading are not instrumented.
100
+
101
+ Generator and dataset calls remain lazy. Each traversal gets a span that starts when the first result is requested and ends on exhaustion, error or explicit `iterator.close()`. Dataset results preserve their length and `DataLoader` compatibility. Starting another traversal preserves the dataset's reset behavior and ends any unfinished span from the previous traversal. The span is current only while producing the next result, not while your application handles it. Close partially consumed iterators to end their spans promptly. Lazy payloads are not collected. Multiprocessing `DataLoader` workers receive the native dataset through serialization, not the instrumentor's tracer provider or parent context; inference in those workers is not traced by this dataset wrapper. To trace inference inside a worker, initialize its own exporter there and add explicit spans around that worker's inference; the parent instrumentor does not trace a deserialized dataset. Streamer spans end when pipeline inference returns, independently of when queued tokens are consumed. When starting a worker thread, propagate OpenTelemetry context explicitly if it should inherit a parent span.
102
+
103
+ Instrumentation is idempotent and supports `TransformersInstrumentor().uninstrument()` and re-instrumentation. It uses your supplied tracer provider without replacing the global provider.
@@ -0,0 +1,83 @@
1
+ # traceAI Transformers
2
+
3
+ Trace local Hugging Face Transformers pipeline inference in Future AGI. For remote Hugging Face InferenceClient calls, use `traceAI-huggingface` instead; the two instrumentors can run together.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install traceAI-transformers torch
9
+ ```
10
+
11
+ Python 3.10–3.13 and Transformers 4.42–5.x are supported. Transformers 5 requires Python 3.11 or later. Use PyTorch pipelines; select the appropriate PyTorch build for your CPU or GPU.
12
+
13
+ ## Trace inference
14
+
15
+ Set `FI_API_KEY` and `FI_SECRET_KEY` in your environment, then configure tracing before calling your pipeline:
16
+
17
+ ```python
18
+ import os
19
+ from fi_instrumentation import register
20
+ from fi_instrumentation.fi_types import ProjectType
21
+ from traceai_transformers import TransformersInstrumentor
22
+ from transformers import pipeline
23
+
24
+ provider = register(
25
+ project_name="local-transformers",
26
+ project_type=ProjectType.OBSERVE,
27
+ headers={
28
+ "FI_API_KEY": os.environ["FI_API_KEY"],
29
+ "FI_SECRET_KEY": os.environ["FI_SECRET_KEY"],
30
+ },
31
+ verbose=False,
32
+ )
33
+ TransformersInstrumentor().instrument(tracer_provider=provider)
34
+
35
+ generate = pipeline(
36
+ "text-generation",
37
+ model="HuggingFaceTB/SmolLM2-135M-Instruct",
38
+ device=-1,
39
+ )
40
+ result = generate(
41
+ [{"role": "user", "content": "Explain what a tokenizer does in one sentence."}],
42
+ max_new_tokens=32,
43
+ do_sample=False,
44
+ )
45
+ print(result[0]["generated_text"][-1]["content"])
46
+ provider.force_flush()
47
+ provider.shutdown()
48
+ ```
49
+
50
+ The first run downloads the model. `register` exports OTLP traces to `https://api.futureagi.com/tracer/v1/traces` with `FI_API_KEY` and `FI_SECRET_KEY` headers. This is a traces-only endpoint, not a destination for OTLP metrics or logs. Open the `local-transformers` project in Future AGI to inspect `transformers.text-generation` spans.
51
+
52
+ ## Content and privacy
53
+
54
+ By default, only task, model architecture, timing, status and error information are recorded. Model paths, generation parameters, embedding vectors and token usage estimates are not collected.
55
+
56
+ To include bounded input/output previews:
57
+
58
+ ```python
59
+ from fi_instrumentation import TraceConfig
60
+
61
+ TransformersInstrumentor().instrument(
62
+ tracer_provider=provider,
63
+ capture_content=True,
64
+ config=TraceConfig(hide_error_details=True),
65
+ )
66
+ ```
67
+
68
+ Choose this configuration on your first `instrument()` call, or call `uninstrument()` before changing it. Previews are limited to 4,096 characters and may be truncated. `TraceConfig` input/output privacy flags override content capture. Hiding inputs also suppresses output previews, because pipeline responses can contain the original prompt or conversation. Set `FI_HIDE_ERROR_DETAILS=true` to omit exception messages, stack traces and error descriptions. Error details can contain inputs even when content capture is off.
69
+
70
+ ## Supported calls
71
+
72
+ | Pipeline | Span kind | Versions |
73
+ | --- | --- | --- |
74
+ | Text generation, including chat, batches and streamers | LLM | 4.42–5.x |
75
+ | Feature extraction, including tensor results | EMBEDDING | 4.42–5.x |
76
+ | Text-to-text generation, summarization and translation | LLM | 4.x only |
77
+ | Extractive question answering | CHAIN | 4.x only |
78
+
79
+ Transformers 5 removed the historical text-to-text, summarization, translation and extractive question-answering pipelines. Use a text-generation chat model on 5.x. Direct `model.generate()` calls, other tasks, TensorFlow pipelines, and model loading are not instrumented.
80
+
81
+ Generator and dataset calls remain lazy. Each traversal gets a span that starts when the first result is requested and ends on exhaustion, error or explicit `iterator.close()`. Dataset results preserve their length and `DataLoader` compatibility. Starting another traversal preserves the dataset's reset behavior and ends any unfinished span from the previous traversal. The span is current only while producing the next result, not while your application handles it. Close partially consumed iterators to end their spans promptly. Lazy payloads are not collected. Multiprocessing `DataLoader` workers receive the native dataset through serialization, not the instrumentor's tracer provider or parent context; inference in those workers is not traced by this dataset wrapper. To trace inference inside a worker, initialize its own exporter there and add explicit spans around that worker's inference; the parent instrumentor does not trace a deserialized dataset. Streamer spans end when pipeline inference returns, independently of when queued tokens are consumed. When starting a worker thread, propagate OpenTelemetry context explicitly if it should inherit a parent span.
82
+
83
+ Instrumentation is idempotent and supports `TransformersInstrumentor().uninstrument()` and re-instrumentation. It uses your supplied tracer provider without replacing the global provider.
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27,<2"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "traceAI-transformers"
7
+ version = "0.1.0"
8
+ description = "OpenTelemetry instrumentation for local Hugging Face Transformers pipelines"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ authors = [{name = "Future AGI", email = "no-reply@futureagi.com"}]
12
+ requires-python = ">=3.10,<3.14"
13
+ dependencies = [
14
+ "fi-instrumentation-otel>=1.2.2,<2",
15
+ "transformers>=4.42,<6",
16
+ "opentelemetry-instrumentation>=0.50b0,<1",
17
+ "wrapt>=1.15,<2",
18
+ ]
19
+
20
+ [project.optional-dependencies]
21
+ dev = ["pytest>=8,<9", "torch>=2.6,<3", "traceAI-huggingface>=0.1.0", "mypy>=1.15,<2"]
22
+
23
+ [project.urls]
24
+ Repository = "https://github.com/future-agi/traceAI/tree/dev/python/frameworks/transformers"
25
+ Documentation = "https://docs.futureagi.com/docs/tracing"
26
+
27
+ [project.entry-points.opentelemetry_instrumentor]
28
+ transformers = "traceai_transformers:TransformersInstrumentor"
29
+
30
+ [tool.hatch.build.targets.wheel]
31
+ packages = ["traceai_transformers"]
32
+
33
+ [tool.pytest.ini_options]
34
+ testpaths = ["tests"]