codegreen 0.4.0__tar.gz → 0.4.2__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.
- {codegreen-0.4.0 → codegreen-0.4.2}/CMakeLists.txt +10 -1
- {codegreen-0.4.0/codegreen.egg-info → codegreen-0.4.2}/PKG-INFO +1 -1
- codegreen-0.4.2/benchmark/_workload_gpt2.py +31 -0
- codegreen-0.4.2/benchmark/_workload_gpt2_session.py +30 -0
- codegreen-0.4.2/benchmark/cg_modes_compare.py +109 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/__init__.py +1 -1
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analyzer/plot.py +6 -6
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/config.json +1 -3
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/language_runtimes/python/codegreen_runtime.py +82 -7
- {codegreen-0.4.0 → codegreen-0.4.2/codegreen.egg-info}/PKG-INFO +1 -1
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen.egg-info/SOURCES.txt +3 -1
- {codegreen-0.4.0 → codegreen-0.4.2}/pyproject.toml +1 -1
- codegreen-0.4.0/benchmark/cg_vs_codecarbon_transformers.py +0 -109
- {codegreen-0.4.0 → codegreen-0.4.2}/LICENSE +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/MANIFEST.in +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/README.md +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/__init__.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/__main__.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/compilers.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/config.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/harness.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/profilers.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/results.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/suites/__init__.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/suites/base.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/suites/benchmarksgame.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/suites/dacapo.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/suites/perfopt.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/suites/renaissance.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/validation/__init__.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/validation/analysis.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/validation/experiments.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/benchmark/validation/reporting.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analysis/__init__.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analysis/_ts_java.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analysis/cfg/__init__.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analysis/cfg/builder.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analysis/cfg/callgraph.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analysis/cfg/dataflow.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analysis/cfg/energy_flow.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analysis/cfg/features.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analysis/cfg/pdg.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analysis/cfg/types.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analysis/cfg/visualization.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/analyzer/__init__.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/cli/__init__.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/cli/cli.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/cli/entrypoint.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/__init__.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/ast_processor.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/bridge_analyze.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/bridge_instrument.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/config.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/configs/TEMPLATE.json +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/configs/c.json +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/configs/cpp.json +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/configs/java.json +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/configs/javascript.json +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/configs/python.json +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/engine.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/language_configs.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/language_engine.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/language_runtimes/c/codegreen_runtime.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/language_runtimes/cpp/codegreen/runtime.hpp +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/language_runtimes/java/codegreen/runtime/CodeGreenRuntime.java +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/instrumentation/language_runtimes/java/codegreen/runtime/CodeGreenStandaloneRuntime.java +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/utils/__init__.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/utils/binary.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen/utils/platform.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen.egg-info/dependency_links.txt +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen.egg-info/entry_points.txt +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen.egg-info/not-zip-safe +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen.egg-info/requires.txt +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/codegreen.egg-info/top_level.txt +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/requirements.txt +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/setup.cfg +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/setup.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/tests/test_instrumentation.py +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/binarytrees/2.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/helloworld/1.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/knucleotide/1.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/mandelbrot/1-ffi.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/mandelbrot/1-mffi.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/nbody/2.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/nbody/5.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/nbody/8-i.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/nsieve/1.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/spectral-norm/3.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/spectral-norm/4.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/spectral-norm/5-im.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/Programming-Language-Benchmarks/bench/algorithm/spectral-norm/6-im.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/aligned_indent.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/array.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/comment.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/compound_lit.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/cond.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/enum.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/expr.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/func.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/if_else.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/issue-1568.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/issue-2086.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/issue-4079.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/issue-4117.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/issue-4525.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/label.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/loop.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/no_braces.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/preproc_cond.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/preproc_func.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/string.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/struct.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/switch.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/ternary.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/indent/c/unfinished_comment.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/nvim-treesitter/tests/query/highlights/c/enums-as-constants.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/crates/cli/src/templates/PARSER_NAME.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/crates/cli/src/templates/py-binding.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/crates/generate/src/templates/alloc.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/crates/generate/src/templates/array.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/crates/highlight/include/tree_sitter/highlight.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/crates/tags/include/tree_sitter/tags.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/CMakeLists.txt +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/binding_web/lib/tree-sitter.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/include/tree_sitter/api.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/alloc.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/alloc.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/array.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/atomic.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/clock.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/error_costs.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/get_changed_ranges.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/get_changed_ranges.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/host.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/language.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/language.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/length.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/lexer.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/lexer.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/lib.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/node.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/parser.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/parser.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/point.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/portable/endian.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/query.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/reduce_action.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/reusable_node.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/stack.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/stack.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/subtree.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/subtree.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/tree.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/tree.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/tree_cursor.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/tree_cursor.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/ts_assert.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/unicode/ptypes.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/unicode/umachine.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/unicode/urename.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/unicode/utf.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/unicode/utf16.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/unicode/utf8.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/unicode.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/wasm/stdlib.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/wasm/wasm-stdlib.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/wasm_store.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/lib/src/wasm_store.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/test/fixtures/test_grammars/depends_on_column/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/test/fixtures/test_grammars/epsilon_external_extra_tokens/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/test/fixtures/test_grammars/epsilon_external_tokens/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/test/fixtures/test_grammars/external_and_internal_anonymous_tokens/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/test/fixtures/test_grammars/external_and_internal_tokens/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/test/fixtures/test_grammars/external_extra_tokens/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/test/fixtures/test_grammars/external_tokens/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/test/fixtures/test_grammars/external_unicode_column_alignment/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/test/fixtures/test_grammars/get_col_eof/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/test/fixtures/test_grammars/get_col_should_hang_not_crash/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/test/fixtures/test_grammars/inverted_external_token/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter/test/fixtures/test_grammars/uses_current_column/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/CMakeLists.txt +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/bindings/c/tree_sitter/tree-sitter-c.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/bindings/python/tree_sitter_c/binding.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/bindings/swift/TreeSitterC/c.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/examples/cluster.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/examples/malloc.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/examples/parser.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/src/parser.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/src/tree_sitter/alloc.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/src/tree_sitter/array.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/src/tree_sitter/parser.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/test/highlight/keywords.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-c/test/highlight/names.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-cpp/CMakeLists.txt +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-cpp/bindings/c/tree-sitter-cpp.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-cpp/bindings/python/tree_sitter_cpp/binding.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-cpp/bindings/swift/TreeSitterCPP/cpp.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-cpp/examples/marker-index.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-cpp/src/parser.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-cpp/src/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-cpp/src/tree_sitter/alloc.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-cpp/src/tree_sitter/array.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-cpp/src/tree_sitter/parser.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-java/CMakeLists.txt +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-java/bindings/c/tree-sitter-java.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-java/bindings/python/tree_sitter_java/binding.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-java/bindings/swift/TreeSitterJava/java.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-java/src/parser.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-java/src/tree_sitter/alloc.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-java/src/tree_sitter/array.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-java/src/tree_sitter/parser.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-python/CMakeLists.txt +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-python/bindings/c/tree-sitter-python.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-python/bindings/python/tree_sitter_python/binding.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-python/bindings/swift/TreeSitterPython/python.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-python/src/parser.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-python/src/scanner.c +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-python/src/tree_sitter/alloc.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-python/src/tree_sitter/array.h +0 -0
- {codegreen-0.4.0 → codegreen-0.4.2}/third_party/tree-sitter-python/src/tree_sitter/parser.h +0 -0
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
cmake_minimum_required(VERSION 3.16)
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
# Single source of truth: pyproject.toml [project].version
|
|
4
|
+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/pyproject.toml" _PYPROJECT_TOML)
|
|
5
|
+
string(REGEX MATCH "version *= *\"([0-9]+\\.[0-9]+\\.[0-9]+)\"" _VERSION_MATCH "${_PYPROJECT_TOML}")
|
|
6
|
+
if(NOT CMAKE_MATCH_1)
|
|
7
|
+
message(FATAL_ERROR "Could not parse [project].version from pyproject.toml")
|
|
8
|
+
endif()
|
|
9
|
+
set(_CODEGREEN_VERSION "${CMAKE_MATCH_1}")
|
|
10
|
+
|
|
11
|
+
project(CodeGreen VERSION ${_CODEGREEN_VERSION} LANGUAGES CXX)
|
|
3
12
|
|
|
4
13
|
set(CMAKE_CXX_STANDARD 17)
|
|
5
14
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""GPT-2 generation workload. Same script is used unchanged across modes."""
|
|
2
|
+
import os, time
|
|
3
|
+
os.environ.setdefault("TRANSFORMERS_VERBOSITY", "error")
|
|
4
|
+
|
|
5
|
+
import torch
|
|
6
|
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
|
7
|
+
|
|
8
|
+
PROMPTS = [
|
|
9
|
+
"Energy-aware computing is",
|
|
10
|
+
"The cheapest way to train a model is",
|
|
11
|
+
"Hardware energy counters report",
|
|
12
|
+
"Modern transformers can be optimized by",
|
|
13
|
+
] * 8 # 32 prompts -> dominates total runtime over import cost
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main():
|
|
17
|
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
18
|
+
tok = GPT2Tokenizer.from_pretrained("gpt2")
|
|
19
|
+
tok.pad_token = tok.eos_token
|
|
20
|
+
tok.padding_side = "left"
|
|
21
|
+
model = GPT2LMHeadModel.from_pretrained("gpt2").to(device).eval()
|
|
22
|
+
batch = tok(PROMPTS, padding=True, return_tensors="pt").to(device)
|
|
23
|
+
t0 = time.perf_counter()
|
|
24
|
+
with torch.no_grad():
|
|
25
|
+
out = model.generate(**batch, max_new_tokens=128, do_sample=False)
|
|
26
|
+
dt = time.perf_counter() - t0
|
|
27
|
+
print(f"workload done: device={device} prompts={len(PROMPTS)} gen_s={dt:.2f}")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if __name__ == "__main__":
|
|
31
|
+
main()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Same workload as cg_workload.py but bracketed under codegreen.Session.
|
|
2
|
+
Measures the same wall-clock span codegreen run measures."""
|
|
3
|
+
import os, time
|
|
4
|
+
os.environ.setdefault("TRANSFORMERS_VERBOSITY", "error")
|
|
5
|
+
|
|
6
|
+
import codegreen
|
|
7
|
+
|
|
8
|
+
with codegreen.Session("whole-script", output_file=os.environ.get("CG_OUT", "/tmp/cg_session_run.json")) as s:
|
|
9
|
+
with s.task("everything"):
|
|
10
|
+
import torch
|
|
11
|
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
|
12
|
+
|
|
13
|
+
PROMPTS = [
|
|
14
|
+
"Energy-aware computing is",
|
|
15
|
+
"The cheapest way to train a model is",
|
|
16
|
+
"Hardware energy counters report",
|
|
17
|
+
"Modern transformers can be optimized by",
|
|
18
|
+
] * 8
|
|
19
|
+
|
|
20
|
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
21
|
+
tok = GPT2Tokenizer.from_pretrained("gpt2")
|
|
22
|
+
tok.pad_token = tok.eos_token
|
|
23
|
+
tok.padding_side = "left"
|
|
24
|
+
model = GPT2LMHeadModel.from_pretrained("gpt2").to(device).eval()
|
|
25
|
+
batch = tok(PROMPTS, padding=True, return_tensors="pt").to(device)
|
|
26
|
+
t0 = time.perf_counter()
|
|
27
|
+
with torch.no_grad():
|
|
28
|
+
out = model.generate(**batch, max_new_tokens=128, do_sample=False)
|
|
29
|
+
dt = time.perf_counter() - t0
|
|
30
|
+
print(f"workload done: device={device} prompts={len(PROMPTS)} gen_s={dt:.2f}")
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Run identical GPT-2 workload through CodeGreen access modes and compare totals.
|
|
2
|
+
|
|
3
|
+
Mode A: `codegreen run` -- whole-program energy via the CLI
|
|
4
|
+
Mode B: `codegreen.Session` (manual span around the entire script body)
|
|
5
|
+
|
|
6
|
+
Both bracket the same wall-clock span, so the readings should agree within
|
|
7
|
+
small noise (no instrumentation overhead from extra checkpoints).
|
|
8
|
+
|
|
9
|
+
A third reference is bare wall-clock (no codegreen) to check timing parity."""
|
|
10
|
+
import json, os, statistics, subprocess, sys, time
|
|
11
|
+
|
|
12
|
+
REPEAT = int(os.environ.get("CG_REPEAT", "3"))
|
|
13
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
14
|
+
WORKLOAD = os.path.join(HERE, "_workload_gpt2.py")
|
|
15
|
+
WORKLOAD_SESSION = os.path.join(HERE, "_workload_gpt2_session.py")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _parse_json_blob(stdout: str) -> dict:
|
|
19
|
+
"""codegreen --json prints multi-line JSON; find the outermost {...} block."""
|
|
20
|
+
s = stdout
|
|
21
|
+
start = s.find("{")
|
|
22
|
+
end = s.rfind("}")
|
|
23
|
+
if start < 0 or end < 0 or end <= start:
|
|
24
|
+
raise RuntimeError(f"no JSON block found in stdout (last 300 chars):\n{s[-300:]}")
|
|
25
|
+
return json.loads(s[start:end + 1])
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def mode_cli_run():
|
|
29
|
+
cmd = ["codegreen", "run", "python", WORKLOAD, "--repeat", "1", "--warmup", "0", "--json"]
|
|
30
|
+
res = subprocess.run(cmd, capture_output=True, text=True, timeout=600)
|
|
31
|
+
if res.returncode != 0:
|
|
32
|
+
raise RuntimeError(f"codegreen run failed:\n{res.stderr[-400:]}")
|
|
33
|
+
d = _parse_json_blob(res.stdout)
|
|
34
|
+
e = d.get("energy_joules", {})
|
|
35
|
+
t = d.get("time_seconds", {})
|
|
36
|
+
energy = e.get("mean") if isinstance(e, dict) else e
|
|
37
|
+
secs = t.get("mean") if isinstance(t, dict) else t
|
|
38
|
+
return {"energy_j": energy, "power_w": d.get("power_watts"), "wall_s": secs,
|
|
39
|
+
"domains": d.get("domains") or {}}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def mode_session():
|
|
43
|
+
out = f"/tmp/_session_{os.getpid()}_{time.time()}.json"
|
|
44
|
+
env = dict(os.environ); env["CG_OUT"] = out
|
|
45
|
+
res = subprocess.run([sys.executable, WORKLOAD_SESSION], env=env, capture_output=True, text=True, timeout=600)
|
|
46
|
+
if res.returncode != 0:
|
|
47
|
+
raise RuntimeError(f"session script failed:\n{res.stderr[-400:]}")
|
|
48
|
+
rep = json.load(open(out))
|
|
49
|
+
task = rep["tasks"][0]
|
|
50
|
+
return {"energy_j": task["energy_j"], "power_w": task["avg_power_w"],
|
|
51
|
+
"wall_s": task["duration_s"], "domains": task["domains"]}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def mode_bare():
|
|
55
|
+
t0 = time.perf_counter()
|
|
56
|
+
res = subprocess.run([sys.executable, WORKLOAD], capture_output=True, text=True, timeout=600)
|
|
57
|
+
dt = time.perf_counter() - t0
|
|
58
|
+
if res.returncode != 0:
|
|
59
|
+
raise RuntimeError(f"bare run failed:\n{res.stderr[-400:]}")
|
|
60
|
+
return {"energy_j": None, "power_w": None, "wall_s": dt, "domains": {}}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def repeat_run(label, fn):
|
|
64
|
+
rows = []
|
|
65
|
+
for _ in range(REPEAT):
|
|
66
|
+
try: rows.append(fn())
|
|
67
|
+
except Exception as e: rows.append({"error": str(e)})
|
|
68
|
+
return label, rows
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def stat(rows, key):
|
|
72
|
+
vs = [r[key] for r in rows if "error" not in r and r.get(key) is not None]
|
|
73
|
+
if not vs: return None
|
|
74
|
+
return statistics.mean(vs), (statistics.stdev(vs) if len(vs) > 1 else 0.0)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def main():
|
|
78
|
+
print(f"GPT-2 workload, {REPEAT} repeats per mode\n")
|
|
79
|
+
rs = []
|
|
80
|
+
for label, fn in [("Bare (timing only)", mode_bare),
|
|
81
|
+
("CLI: codegreen run", mode_cli_run),
|
|
82
|
+
("Session (manual)", mode_session)]:
|
|
83
|
+
print(f"-- running {label}")
|
|
84
|
+
rs.append(repeat_run(label, fn))
|
|
85
|
+
|
|
86
|
+
print(f"\n{'mode':<22} {'energy_j (mean +/- std)':<28} {'power_w':<10} {'wall_s':<14} runs")
|
|
87
|
+
print("-" * 92)
|
|
88
|
+
base_e = base_w = None
|
|
89
|
+
for label, rows in rs:
|
|
90
|
+
ok = [r for r in rows if "error" not in r]
|
|
91
|
+
e = stat(rows, "energy_j"); p = stat(rows, "power_w"); w = stat(rows, "wall_s")
|
|
92
|
+
if not ok:
|
|
93
|
+
print(f"{label:<22} ERROR")
|
|
94
|
+
continue
|
|
95
|
+
if e and base_e is None and "Session" not in label and "CLI" in label:
|
|
96
|
+
base_e = e[0]
|
|
97
|
+
if w and base_w is None: base_w = w[0]
|
|
98
|
+
e_str = f"{e[0]:>9.2f} +/- {e[1]:<6.2f}" if e else " n/a "
|
|
99
|
+
e_pct = f"({100*(e[0]-base_e)/base_e:+5.2f}%)" if (e and base_e) else " "
|
|
100
|
+
p_str = f"{p[0]:>5.1f} W" if p else " n/a "
|
|
101
|
+
w_str = f"{w[0]:>4.2f} s ({100*(w[0]-base_w)/base_w:+4.1f}%)" if (w and base_w) else f"{w[0]:>4.2f} s"
|
|
102
|
+
print(f"{label:<22} {e_str} J {e_pct} {p_str:<10} {w_str:<14} {len(ok)}/{REPEAT}")
|
|
103
|
+
|
|
104
|
+
json.dump({"repeat": REPEAT, "results": rs}, open("/tmp/cg_modes_compare.json", "w"), indent=2, default=str)
|
|
105
|
+
print(f"\nraw JSON: /tmp/cg_modes_compare.json")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
if __name__ == "__main__":
|
|
109
|
+
main()
|
|
@@ -12,7 +12,7 @@ try:
|
|
|
12
12
|
from importlib.metadata import version as _pkg_version
|
|
13
13
|
__version__ = _pkg_version("codegreen")
|
|
14
14
|
except Exception:
|
|
15
|
-
__version__ = "0.4.
|
|
15
|
+
__version__ = "0.4.2" # fallback for dev/editable installs
|
|
16
16
|
__author__ = "Saurabhsingh Rajput"
|
|
17
17
|
__email__ = "saurabh@dal.ca"
|
|
18
18
|
__description__ = "Know the true energy cost of your code"
|
|
@@ -272,11 +272,11 @@ def _render_session_plotly(tasks: list, path: Path) -> None:
|
|
|
272
272
|
except ImportError:
|
|
273
273
|
return
|
|
274
274
|
fig = go.Figure()
|
|
275
|
-
t0_ns = min(s["
|
|
275
|
+
t0_ns = min(s["t_ns"] for t in tasks for s in t["timeseries"])
|
|
276
276
|
for t in tasks:
|
|
277
277
|
ts = t["timeseries"]
|
|
278
|
-
x = [(s["
|
|
279
|
-
y = [s["
|
|
278
|
+
x = [(s["t_ns"] - t0_ns) / 1e9 for s in ts]
|
|
279
|
+
y = [s["power_w"] for s in ts]
|
|
280
280
|
fig.add_trace(go.Scatter(
|
|
281
281
|
x=x, y=y, mode="lines", name=t["name"],
|
|
282
282
|
line=dict(width=1),
|
|
@@ -302,11 +302,11 @@ def _render_session_matplotlib(tasks: list, path: Path) -> None:
|
|
|
302
302
|
return
|
|
303
303
|
fig, ax = plt.subplots(figsize=(10, 4), facecolor=BG)
|
|
304
304
|
ax.set_facecolor(CARD)
|
|
305
|
-
t0_ns = min(s["
|
|
305
|
+
t0_ns = min(s["t_ns"] for t in tasks for s in t["timeseries"])
|
|
306
306
|
for t in tasks:
|
|
307
307
|
ts = t["timeseries"]
|
|
308
|
-
x = [(s["
|
|
309
|
-
y = [s["
|
|
308
|
+
x = [(s["t_ns"] - t0_ns) / 1e9 for s in ts]
|
|
309
|
+
y = [s["power_w"] for s in ts]
|
|
310
310
|
ax.plot(x, y, lw=0.8, label=t["name"])
|
|
311
311
|
ax.set_xlabel("Time (s)", color=TXT)
|
|
312
312
|
ax.set_ylabel("Power (W)", color=TXT)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.3.16",
|
|
3
2
|
"paths": {
|
|
4
3
|
"runtime_modules": {
|
|
5
4
|
"python": "runtime/codegreen_runtime.py",
|
|
@@ -165,7 +164,6 @@
|
|
|
165
164
|
"completed": false,
|
|
166
165
|
"timestamp": null,
|
|
167
166
|
"environment_type": "unknown",
|
|
168
|
-
"detected_sensors": []
|
|
169
|
-
"version": "0.3.16"
|
|
167
|
+
"detected_sensors": []
|
|
170
168
|
}
|
|
171
169
|
}
|
|
@@ -255,6 +255,7 @@ import functools
|
|
|
255
255
|
import os as _os
|
|
256
256
|
import sys as _sys
|
|
257
257
|
import warnings as _warnings
|
|
258
|
+
import statistics as _statistics
|
|
258
259
|
from contextlib import contextmanager as _contextmanager
|
|
259
260
|
|
|
260
261
|
_active_session: Optional["Session"] = None
|
|
@@ -332,6 +333,7 @@ class TaskResult:
|
|
|
332
333
|
parent: Optional[str]
|
|
333
334
|
domains: Dict[str, float]
|
|
334
335
|
timeseries: Optional[List[Dict[str, float]]] = None # [{t_ns,j,w,d:{...}}]
|
|
336
|
+
noise: Optional[Dict[str, float]] = None # populated when timeseries present
|
|
335
337
|
|
|
336
338
|
|
|
337
339
|
# Sample size estimate (matches SynchronizedReading on 64-bit) for buffer sizing
|
|
@@ -339,6 +341,52 @@ _BYTES_PER_SAMPLE_EST = 800
|
|
|
339
341
|
_DEFAULT_SAMPLE_INTERVAL_MS = 10 # NEMB default; mirror in Session for sizing math
|
|
340
342
|
|
|
341
343
|
|
|
344
|
+
def _bundled_sample_interval_ms() -> int:
|
|
345
|
+
"""Read the C++ NEMB default sample interval from bundled config.json."""
|
|
346
|
+
cfg = Path(__file__).resolve().parents[3] / "config.json"
|
|
347
|
+
try:
|
|
348
|
+
with open(cfg) as f:
|
|
349
|
+
d = json.load(f)
|
|
350
|
+
return int(d.get("coordinator", {}).get("measurement_interval_ms", 1))
|
|
351
|
+
except Exception:
|
|
352
|
+
return 1
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def _quality_label(cv_percent: float) -> str:
|
|
356
|
+
if cv_percent < 2.0: return "excellent"
|
|
357
|
+
if cv_percent < 5.0: return "good"
|
|
358
|
+
if cv_percent < 10.0: return "moderate"
|
|
359
|
+
return "high-noise"
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def _compute_task_noise(task: "TaskResult", sample_interval_ms: int) -> Optional[Dict]:
|
|
363
|
+
"""Power-CV + sample-drop summary for one task. None if no time-series."""
|
|
364
|
+
ts = task.timeseries
|
|
365
|
+
if not ts:
|
|
366
|
+
return None
|
|
367
|
+
powers = [s.get("power_w", 0.0) for s in ts if s.get("power_w") is not None]
|
|
368
|
+
n = len(powers)
|
|
369
|
+
if n >= 2:
|
|
370
|
+
mean_w = _statistics.fmean(powers)
|
|
371
|
+
std_w = _statistics.pstdev(powers, mean_w) if mean_w > 0 else 0.0
|
|
372
|
+
else:
|
|
373
|
+
mean_w = powers[0] if n == 1 else 0.0
|
|
374
|
+
std_w = 0.0
|
|
375
|
+
cv = (100.0 * std_w / mean_w) if mean_w > 0 else 0.0
|
|
376
|
+
expected = max(1, int(round(task.duration_s * 1000.0 / max(1, sample_interval_ms))))
|
|
377
|
+
drop_ratio = max(0.0, 1.0 - n / expected)
|
|
378
|
+
return {
|
|
379
|
+
"samples_captured": n,
|
|
380
|
+
"samples_expected": expected,
|
|
381
|
+
"drop_ratio": round(drop_ratio, 4),
|
|
382
|
+
"power_mean_w": round(mean_w, 4),
|
|
383
|
+
"power_std_w": round(std_w, 4),
|
|
384
|
+
"power_cv_percent": round(cv, 3),
|
|
385
|
+
"sample_interval_ms": sample_interval_ms,
|
|
386
|
+
"quality": _quality_label(cv),
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
|
|
342
390
|
class Session:
|
|
343
391
|
"""Manual span-based energy measurement.
|
|
344
392
|
|
|
@@ -455,6 +503,9 @@ class Session:
|
|
|
455
503
|
)
|
|
456
504
|
except Exception:
|
|
457
505
|
pass
|
|
506
|
+
# Effective sample interval for noise / drop-ratio math.
|
|
507
|
+
self._sample_interval_ms = int(sample_interval_ms) if sample_interval_ms is not None \
|
|
508
|
+
else _bundled_sample_interval_ms()
|
|
458
509
|
self._sampling_mode = sampling_mode # "adaptive" reserved for future
|
|
459
510
|
|
|
460
511
|
def start(self) -> "Session":
|
|
@@ -498,7 +549,7 @@ class Session:
|
|
|
498
549
|
return 0
|
|
499
550
|
with self._ts_lock:
|
|
500
551
|
self._ts_samples.extend(samples)
|
|
501
|
-
self._ts_last_ts = samples[-1]["
|
|
552
|
+
self._ts_last_ts = samples[-1]["t_ns"]
|
|
502
553
|
return len(samples)
|
|
503
554
|
|
|
504
555
|
def _drain_loop(self):
|
|
@@ -608,7 +659,7 @@ class Session:
|
|
|
608
659
|
self._drain_once() # ensure latest samples are pulled before filtering
|
|
609
660
|
with self._ts_lock:
|
|
610
661
|
ts = [s for s in self._ts_samples
|
|
611
|
-
if t_mono_ns <= s["
|
|
662
|
+
if t_mono_ns <= s["t_ns"] <= t_end_mono_ns]
|
|
612
663
|
result = TaskResult(
|
|
613
664
|
name=name, energy_j=e.value, avg_power_w=p.value,
|
|
614
665
|
duration_s=dur.value if dur.value > 0 else (t_end - t_start),
|
|
@@ -650,14 +701,32 @@ class Session:
|
|
|
650
701
|
return self._finalized_report
|
|
651
702
|
total_e = sum(t.energy_j for t in self._tasks if t.depth == 0)
|
|
652
703
|
total_d = (time.time() - self._t0_wall) if self._started else 0.0
|
|
704
|
+
warnings_list: List[str] = []
|
|
705
|
+
worst_cv = 0.0
|
|
706
|
+
for t in self._tasks:
|
|
707
|
+
if t.timeseries:
|
|
708
|
+
t.noise = _compute_task_noise(t, self._sample_interval_ms)
|
|
709
|
+
if t.noise:
|
|
710
|
+
cv = t.noise["power_cv_percent"]
|
|
711
|
+
drop = t.noise["drop_ratio"]
|
|
712
|
+
if cv > worst_cv: worst_cv = cv
|
|
713
|
+
if cv >= 10.0 or drop >= 0.20:
|
|
714
|
+
msg = (f"task '{t.name}': noisy reading "
|
|
715
|
+
f"(power CV={cv:.1f}%, sample drop={drop*100:.1f}%, "
|
|
716
|
+
f"quality={t.noise['quality']})")
|
|
717
|
+
warnings_list.append(msg)
|
|
718
|
+
_warnings.warn("codegreen: " + msg, RuntimeWarning, stacklevel=4)
|
|
719
|
+
totals = {
|
|
720
|
+
"energy_j": total_e,
|
|
721
|
+
"duration_s": total_d,
|
|
722
|
+
"n_tasks": len(self._tasks),
|
|
723
|
+
"worst_power_cv_percent": round(worst_cv, 3) if self._record_ts else None,
|
|
724
|
+
"noise_warnings": warnings_list,
|
|
725
|
+
}
|
|
653
726
|
report = {
|
|
654
727
|
"session_name": self.name,
|
|
655
728
|
"tasks": [t.__dict__ for t in self._tasks],
|
|
656
|
-
"totals":
|
|
657
|
-
"energy_j": total_e,
|
|
658
|
-
"duration_s": total_d,
|
|
659
|
-
"n_tasks": len(self._tasks),
|
|
660
|
-
},
|
|
729
|
+
"totals": totals,
|
|
661
730
|
"providers": [],
|
|
662
731
|
"abi_version": self._client.lib.nemb_abi_version() if not self._noop else 0,
|
|
663
732
|
}
|
|
@@ -707,13 +776,19 @@ class Session:
|
|
|
707
776
|
"session", "task", "depth", "parent",
|
|
708
777
|
"energy_j", "avg_power_w", "duration_s",
|
|
709
778
|
"started_at", "ended_at", "domains_json",
|
|
779
|
+
"power_cv_percent", "samples_captured", "samples_expected",
|
|
780
|
+
"drop_ratio", "quality",
|
|
710
781
|
])
|
|
711
782
|
for t in self._tasks:
|
|
783
|
+
n = t.noise or {}
|
|
712
784
|
w.writerow([
|
|
713
785
|
self.name, t.name, t.depth, t.parent or "",
|
|
714
786
|
f"{t.energy_j:.9f}", f"{t.avg_power_w:.6f}", f"{t.duration_s:.6f}",
|
|
715
787
|
f"{t.started_at:.6f}", f"{t.ended_at:.6f}",
|
|
716
788
|
json.dumps(t.domains, separators=(",", ":")),
|
|
789
|
+
n.get("power_cv_percent", ""), n.get("samples_captured", ""),
|
|
790
|
+
n.get("samples_expected", ""), n.get("drop_ratio", ""),
|
|
791
|
+
n.get("quality", ""),
|
|
717
792
|
])
|
|
718
793
|
|
|
719
794
|
@property
|
|
@@ -7,7 +7,9 @@ requirements.txt
|
|
|
7
7
|
setup.py
|
|
8
8
|
benchmark/__init__.py
|
|
9
9
|
benchmark/__main__.py
|
|
10
|
-
benchmark/
|
|
10
|
+
benchmark/_workload_gpt2.py
|
|
11
|
+
benchmark/_workload_gpt2_session.py
|
|
12
|
+
benchmark/cg_modes_compare.py
|
|
11
13
|
benchmark/compilers.py
|
|
12
14
|
benchmark/config.py
|
|
13
15
|
benchmark/harness.py
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"""Verify codegreen.Session against CodeCarbon EmissionsTracker on a transformers
|
|
2
|
-
fine-tune (mirrors https://docs.codecarbon.io/latest/how-to/transformers/).
|
|
3
|
-
|
|
4
|
-
Trackers run **sequentially** (not concurrent) to avoid double-instrumentation noise:
|
|
5
|
-
|
|
6
|
-
Phase 1: CodeCarbon-only -> 1 fine-tune (baseline reference)
|
|
7
|
-
Phase 2: CodeGreen-only -> 3 fine-tunes inside one Session, one per API form:
|
|
8
|
-
explicit start_task / stop_task
|
|
9
|
-
`with sess.task(...)` context manager
|
|
10
|
-
`@codegreen.task(...)` decorator
|
|
11
|
-
|
|
12
|
-
Each fine-tune trains on the same IMDB slice with the same TrainingArguments,
|
|
13
|
-
so per-task CG energy / time / power are directly comparable to the CC baseline.
|
|
14
|
-
|
|
15
|
-
Run: python -m benchmark.cg_vs_codecarbon_transformers [--n 128] [--epochs 1] [--batch 8]
|
|
16
|
-
"""
|
|
17
|
-
import argparse, json, os, time
|
|
18
|
-
|
|
19
|
-
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
|
|
20
|
-
os.environ.setdefault("TRANSFORMERS_VERBOSITY", "error")
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def _build_dataset_and_model_factory(model_name, n):
|
|
24
|
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
25
|
-
from datasets import load_dataset
|
|
26
|
-
tok = AutoTokenizer.from_pretrained(model_name)
|
|
27
|
-
ds = load_dataset("imdb", split=f"train[:{n}]")
|
|
28
|
-
ds = ds.map(lambda b: tok(b["text"], truncation=True, padding="max_length", max_length=128), batched=True)
|
|
29
|
-
ds = ds.rename_column("label", "labels")
|
|
30
|
-
ds.set_format("torch", columns=["input_ids", "attention_mask", "labels"])
|
|
31
|
-
return ds, lambda: AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=2)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def _train_args(out, epochs, batch):
|
|
35
|
-
from transformers import TrainingArguments
|
|
36
|
-
return TrainingArguments(output_dir=out, num_train_epochs=epochs,
|
|
37
|
-
per_device_train_batch_size=batch, save_strategy="no",
|
|
38
|
-
report_to=[], disable_tqdm=True, logging_strategy="no", use_cpu=True)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def _do_train(new_model, ds, out, epochs, batch):
|
|
42
|
-
from transformers import Trainer
|
|
43
|
-
Trainer(model=new_model(), args=_train_args(out, epochs, batch), train_dataset=ds).train()
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def main():
|
|
47
|
-
p = argparse.ArgumentParser()
|
|
48
|
-
p.add_argument("--n", type=int, default=128)
|
|
49
|
-
p.add_argument("--epochs", type=int, default=1)
|
|
50
|
-
p.add_argument("--batch", type=int, default=8)
|
|
51
|
-
p.add_argument("--out", default="/tmp/cg_session.json")
|
|
52
|
-
p.add_argument("--model", default="distilbert-base-uncased")
|
|
53
|
-
args = p.parse_args()
|
|
54
|
-
|
|
55
|
-
ds, new_model = _build_dataset_and_model_factory(args.model, args.n)
|
|
56
|
-
|
|
57
|
-
# ---- Phase 1: CodeCarbon-only baseline ----
|
|
58
|
-
from codecarbon import EmissionsTracker
|
|
59
|
-
cc = EmissionsTracker(project_name="cg_vs_cc", output_dir="/tmp",
|
|
60
|
-
log_level="error", save_to_file=False)
|
|
61
|
-
cc.start()
|
|
62
|
-
t0 = time.perf_counter()
|
|
63
|
-
_do_train(new_model, ds, "/tmp/_cc", args.epochs, args.batch)
|
|
64
|
-
cc_wall = time.perf_counter() - t0
|
|
65
|
-
co2 = cc.stop()
|
|
66
|
-
cc_j = (cc.final_emissions_data.energy_consumed or 0.0) * 3.6e6
|
|
67
|
-
|
|
68
|
-
# ---- Phase 2: CodeGreen Session (3 forms in one session, sequential) ----
|
|
69
|
-
import codegreen
|
|
70
|
-
sess = codegreen.Session(output_file=args.out, record_time_series=True)
|
|
71
|
-
sess.start()
|
|
72
|
-
t0 = time.perf_counter()
|
|
73
|
-
|
|
74
|
-
sess.start_task("explicit_train")
|
|
75
|
-
_do_train(new_model, ds, "/tmp/_t1", args.epochs, args.batch)
|
|
76
|
-
sess.stop_task("explicit_train")
|
|
77
|
-
|
|
78
|
-
with sess.task("context_train"):
|
|
79
|
-
_do_train(new_model, ds, "/tmp/_t2", args.epochs, args.batch)
|
|
80
|
-
|
|
81
|
-
@codegreen.task("decorator_train")
|
|
82
|
-
def fine_tune():
|
|
83
|
-
_do_train(new_model, ds, "/tmp/_t3", args.epochs, args.batch)
|
|
84
|
-
fine_tune()
|
|
85
|
-
|
|
86
|
-
cg_wall = time.perf_counter() - t0
|
|
87
|
-
sess.stop()
|
|
88
|
-
|
|
89
|
-
rep = json.load(open(args.out))
|
|
90
|
-
tasks = {t["name"]: t for t in rep["tasks"]}
|
|
91
|
-
cg_total_tasks = sum(t["energy_j"] for t in rep["tasks"])
|
|
92
|
-
|
|
93
|
-
# Per-task delta vs CC baseline (CC ran 1 train; each CG task ran 1 train)
|
|
94
|
-
print(f"\n{args.model} | IMDB[:{args.n}] | {args.epochs} ep | batch={args.batch}\n")
|
|
95
|
-
print(f"Phase 1 (CodeCarbon, 1 train)")
|
|
96
|
-
print(f" wall {cc_wall:.2f} s energy {cc_j:.2f} J power {cc_j/cc_wall:.2f} W CO2 {co2*1000:.4f} g")
|
|
97
|
-
print(f"\nPhase 2 (CodeGreen Session, 3 trains sequential)")
|
|
98
|
-
print(f" total span energy {rep['total']['energy_j']:.2f} J power {rep['total']['power_w']:.2f} W wall {cg_wall:.2f} s")
|
|
99
|
-
print(f"\n task energy(J) dur(s) power(W) ts delta-vs-CC")
|
|
100
|
-
for name in ("explicit_train", "context_train", "decorator_train"):
|
|
101
|
-
t = tasks[name]
|
|
102
|
-
ts = len(t.get("time_series", []))
|
|
103
|
-
d = 100 * (t["energy_j"] - cc_j) / cc_j if cc_j else float("nan")
|
|
104
|
-
print(f" {name:<18} {t['energy_j']:>8.2f} {t['duration_s']:>6.2f} {t['power_w']:>7.2f} {ts:>5} {d:+7.2f}%")
|
|
105
|
-
print(f"\n domains captured: {list(tasks['explicit_train'].get('per_domain', {}).keys())}")
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if __name__ == "__main__":
|
|
109
|
-
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|