Comments (10)
this seems to have constant deltas @matthewfeickert
import time
import tensorflow as tf
import pyhf.tensor
import pyhf.simplemodels
for i in range(10):
tfb = pyhf.tensor.tensorflow_backend.tensorflow_backend()
tfb.session = tf.Session()
pyhf.set_backend(tfb)
now = time.time()
p = pyhf.simplemodels.hepdata_like([7.],[50.],[7.])
pyhf.runOnePoint(1.0, [50.] + p.config.auxdata, p, p.config.suggested_init(), p.config.suggested_bounds())
delta = time.time() - now
print(delta)
tf.reset_default_graph()
from pyhf.
so I think in order to reset cleanly only this is necessary
tf.reset_default_graph()
pyhf.tensorlib.session = tf.Session()
from pyhf.
pasting the snippet from https://github.com/diana-hep/pyhf/issues/77
def benchmark_backend(backend, n_bins, n_runs=5):
default_backend = pyhf.tensorlib
pyhf.set_backend(backend)
times = [[time_runOnePoint(bins) for bins in n_bins]
for _ in range(n_runs)]
# Reset backend
pyhf.set_backend(default_backend)
return summary_stats(times)
can you try factoring out the pyhf.set_backend
part i.e. just
def benchmark_backend(n_bins, n_runs=5):
times = [[time_runOnePoint(bins) for bins in n_bins]
for _ in range(n_runs)]
return summary_stats(times)
default_backend = pyhf.tensorlib
pyhf.set_backend(backend)
benchmark_backend(.., ...)
pyhf.set_backend(default_backend)
from pyhf.
@lukasheinrich Still seeing it with this
def benchmark_backend(n_bins, n_runs):
times = [[time_runOnePoint(bins) for bins in n_bins]
for _ in range(n_runs)]
return summary_stats(times)
def run_benchmark(n_bins, n_runs=5, file_name='times'):
# following is slightly abridged as writing to dictionaries is taken out for space
default_backend = pyhf.tensorlib
pyhf.set_backend(numpy_backend())
t_mean, t_min, t_max, t_std = benchmark_backend(n_bins, n_runs)
pyhf.set_backend(tensorflow_backend(session=tf.Session()))
t_mean, t_min, t_max, t_std = benchmark_backend(n_bins, n_runs)
pyhf.set_backend(pytorch_backend())
t_mean, t_min, t_max, t_std = benchmark_backend(n_bins, n_runs)
# Reset backend
pyhf.set_backend(default_backend)
from pyhf.
I think we might to reset the TF graph / session on each run. This might be related
but it does seem like TF is just slower even on the first iteration. this is the code i'm testing
import time
import tensorflow as tf
import pyhf.tensor
import pyhf.simplemodels
tfb = pyhf.tensor.tensorflow_backend.tensorflow_backend()
tfb.session = tf.Session()
p = pyhf.simplemodels.hepdata_like([7.],[50.],[7.])
pyhf.set_backend(tfb)
for i in range(10):
now = time.time()
pyhf.runOnePoint(1.0, [50.] + p.config.auxdata, p, p.config.suggested_init(), p.config.suggested_bounds())
delta = time.time() - now
print(delta)
from pyhf.
Indeed, pretty consistent. 👍 I'll implement this in the benchmarks later this evening.
from pyhf.
Yeah, that's what I just found too.
from pyhf.
once we get more familiarity, it might be useful to implement a tensorlib.reset(), but for now it probably good to keep these things explicit, also if people want to use pyhf as part of a larger graph, we probably should mess with it or the session
from pyhf.
@lukasheinrich Indeed, that's a good idea. Can you open up a tensorlib.reset()
Issue (for future work)?
from pyhf.
Yeah, resetting the graph and session fixes it. Closing now. Thanks, @lukasheinrich!
from pyhf.
Related Issues (20)
- Release v0.7.4 checklist HOT 1
- Default POI name for model construction
- Document / summarize additional tools in the "family" / network
- Allow for disabling the default backend in tests at the command line
- Construction of qmutilde for muhat < 0 HOT 6
- jsonschema cannot find path specified \\1.0.0\\def.json HOT 7
- Add basic testing for Windows
- Use `tmp_path` pytest fixture over `tmpdir`
- Make tests/test_scripts.py that use pytest-console-scripts script_runner fixture OS independent HOT 1
- Release v0.7.5 checklist
- Python 3.12 support tracking HOT 5
- Pruning with logical "and" instead of "or" HOT 2
- Catch 100% normalization uncertainty modifiers
- Remove `InvalidNameReuse` exception in favor of in `InvalidModel`
- Typing for tensor shapes
- `ValueError: The truth value of an array` ... when using `fixed_params` kwarg for `pyhf.infer.hypotest` HOT 4
- Release v0.7.6 checklist
- Using the hessian matrix in optimization HOT 2
- Typo in docs for qmutilde test-statistic
- Implementation of fixed params in scipy minimizer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyhf.