Giter Club home page Giter Club logo

Comments (10)

lukasheinrich avatar lukasheinrich commented on May 16, 2024 1

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.

lukasheinrich avatar lukasheinrich commented on May 16, 2024 1

so I think in order to reset cleanly only this is necessary

  tf.reset_default_graph()
  pyhf.tensorlib.session = tf.Session()

from pyhf.

lukasheinrich avatar lukasheinrich commented on May 16, 2024

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.

matthewfeickert avatar matthewfeickert commented on May 16, 2024

@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)

benchmark_times_alt_log

from pyhf.

lukasheinrich avatar lukasheinrich commented on May 16, 2024

I think we might to reset the TF graph / session on each run. This might be related

tensorflow/tensorflow#1439

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.

matthewfeickert avatar matthewfeickert commented on May 16, 2024

Indeed, pretty consistent. 👍 I'll implement this in the benchmarks later this evening.

from pyhf.

matthewfeickert avatar matthewfeickert commented on May 16, 2024

Yeah, that's what I just found too.

from pyhf.

lukasheinrich avatar lukasheinrich commented on May 16, 2024

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.

matthewfeickert avatar matthewfeickert commented on May 16, 2024

@lukasheinrich Indeed, that's a good idea. Can you open up a tensorlib.reset() Issue (for future work)?

from pyhf.

matthewfeickert avatar matthewfeickert commented on May 16, 2024

Yeah, resetting the graph and session fixes it. Closing now. Thanks, @lukasheinrich!

n_runs=5 per binning point:
benchmark_times_resettf_log

from pyhf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.