Sep 9–12, 2019

Hands-on machine learning with Kafka-based streaming pipelines

Boris Lublinsky (Lightbend), Dean Wampler (Lightbend)
1:30pm5:00pm Tuesday, September 10, 2019
Location: LL21 C/D

Who is this presentation for?

  • Software engineers and architects looking to implement production-grade model serving

Level

Intermediate

Description

One possibility of training and serving (scoring) models is to treat trained model as code, then run that code for scoring. This works fine if the model never changes for the lifetime of the scoring process, but isn’t ideal with long-running data streams, where you’d like to retrain the model periodically (due to concept drift) and score with the new model. The better way is to treat the model as data and have this model data exchanged between the training and scoring systems, which allows updating models in the running context.

Boris Lublinsky and Dean Wampler explore different approaches to model training and serving that use this technique, where one or both functions are made an integrated part of the data-processing pipeline implementation (i.e., as an additional functional transformation of the data). The advantage of this approach is that model serving is implemented as part of the larger data-transformation pipeline. Such pipelines can be implemented using streaming engines, for example, Spark Streaming, Flink, or Beam, or streaming libraries, for example Akka Streams or Kafka Streams. Boris and Dean will use Akka Streams, Flink, and Spark Structured Streaming in their demos.

Outline:

Speculative execution of model serving
Guaranteed execution time

  • With several models, where the fastest one provides a fixed execution time for scoring, it’s possible to ensure that scoring completes within a fixed time bound (latency budget), as long as this bound is larger than the execution time of the faster model with the fixed execution time.

Consensus-based model serving

  • With several models, you can implement model serving where the score is the outcome of a majority “vote” of the models.

Quality-based model serving

  • With multiple models, you can layer over them an algorithm that evaluates the quality of scoring result and picks the result with the best quality, which requires a quality metric to exist; may have confidence level on each score and the result with the highest confidence “wins.”
  • You may also wish to implement A/B or blue/green testing, where you put a new model in production and route some percentage of traffic to it, then evaluate if it’s actually better before switching all traffic to it.

Model training
Performance optimizations

  • Training from scratch requires all relevant historical data, so much more compute is required than is typically necessary for scoring; to avoid this, sometimes incremental training updates can be done instead.
  • Mini-batch training has existed for a while as a technique for training models on very large data sets, independent of the notion of streaming, which is directly applicable to the streaming context, where new data arrives all the time.
  • Training a sophisticated model, such as a neural net, and then training a simpler model, such as a logistic regression, and using the neural net as a data generator is another common approach; the simpler model approximates the complex model, trading accuracy for better scoring performance—a variation is to use both models in the speculative execution, latency-sensitive context mentioned above.
  • Advantages of separating training and serving into two different systems include more implementation flexibility and the ability to optimize training and serving independently.
  • Use batch or mini-batch training to save the intermediate model locally to restart training.
  • Train on a dedicated cluster where the hardware and software are optimized for model training.
  • Leverage existing, publicly available models for well-known domains like native language processing (NLP), where updates to the model are rarely required, eliminating the need to do training yourself.

Real-world production concerns
Data governance metadata

  • Organizations will want some traceability about scoring and will want to know which version of a model was used to score each record. This can be implemented several ways
    • Include a version label or universally unique identifier (UUID) for the model with the score that’s added to the records.
    • Use the timestamp and a repository that maps timestamps to model versions to determine the model that was used. However, this is tricky, because you will have to careful track at which subsecond timestamp a new model was added to the system. This approach also won’t really work with in speculative execution scenarios.

Management and monitoring

  • Reactive principles: Availability requirements and how to meet them (e.g., failover to parallel pipeline?) and how and when to scale as needed.

Prerequisite knowledge

  • General knowledge of programming (Scala or Java) and stream processing
  • A basic understanding of model training and serving

Materials or downloads needed in advance

  • A GitHub repository

What you'll learn

  • Learn to prepare a model for serving and to implement streaming pipelines for model serving
  • Understand additional improvements leveraging speculative model serving and additional architectural requirements for building production model serving
Photo of Boris Lublinsky

Boris Lublinsky

Lightbend

Boris Lublinsky is a software architect at Lightbend, where he specializes in big data, stream processing, and services. Boris has over 30 years’ experience in enterprise architecture. Over his career, he’s been responsible for setting architectural direction, conducting architecture assessments, and creating and executing architectural road maps in fields such as big data (Hadoop-based) solutions, service-oriented architecture (SOA), business process management (BPM), and enterprise application integration (EAI). Boris is the coauthor of Applied SOA: Service-Oriented Architecture and Design Strategies, Professional Hadoop Solutions, and Serving Machine Learning Models. He’s also cofounder of and frequent speaker at several Chicago user groups.

Photo of Dean Wampler

Dean Wampler

Lightbend

Dean Wampler is the vice president of fast data engineering at Lightbend, where he leads the Lightbend Fast Data Platform project, a distribution of scalable, distributed stream processing tools including Spark, Flink, Kafka, and Akka, with machine learning and management tools. Dean is the author of Programming Scala and Functional Programming for Java Developers and the coauthor of Programming Hive, all from O’Reilly. He’s a contributor to several open source projects. A frequent Strata speaker, he’s also the co-organizer of several conferences around the world and several user groups in Chicago.

Leave a Comment or Question

Help us make this conference the best it can be for you. Have questions you'd like this speaker to address? Suggestions for issues that deserve extra attention? Feedback that you'd like to share with the speaker and other attendees?

Join the conversation here (requires login)

Contact us

confreg@oreilly.com

For conference registration information and customer service

partners@oreilly.com

For more information on community discounts and trade opportunities with O’Reilly conferences

Become a sponsor

For information on exhibiting or sponsoring a conference

Contact list

View a complete list of O'Reilly AI contacts