示例#1
0
        def create_eviction_policy(model_prob):
            """Creates the appropriate eviction policy for collecting data.

      Args:
        model_prob (float): the returned policy is a mixture of the learned
        eviction policy and the oracle policy, where the learned eviction policy
        is played model_prob of the time.

      Returns:
        EvictionPolicy
      """
            # Need to update the eviction policy and keep the cache state around
            oracle_scorer = {
                "lru": eviction_policy.LRUScorer(),
                "belady": eviction_policy.BeladyScorer(trace),
            }[FLAGS.oracle_eviction_policy]
            learned_scorer = model_eviction_policy.LearnedScorer(
                eviction_model)

            # Use scoring_policy_index = 0 to always get scores from the oracle scorer
            scoring_policy_index = 0 if use_oracle_scores else None
            return eviction_policy.MixturePolicy(
                [
                    eviction_policy.GreedyEvictionPolicy(oracle_scorer),
                    eviction_policy.GreedyEvictionPolicy(learned_scorer)
                ],
                [1 - model_prob, model_prob],
                scoring_policy_index=scoring_policy_index,
            )
示例#2
0
            def scorer_from_config(config, trace):
                """Creates an eviction_policy.CacheLineScorer from the config.

        Args:
          config (Config): config for the cache line scorer.
          trace (MemoryTrace): see get_eviction_policy.

        Returns:
          CacheLineScorer
        """
                scorer_type = config.get("type")
                if scorer_type == "lru":
                    return eviction_policy_mod.LRUScorer()
                elif scorer_type == "belady":
                    return eviction_policy_mod.BeladyScorer(trace)
                elif scorer_type == "learned":
                    with open(config.get("config_path"), "r") as model_config:
                        return (model_eviction_policy_mod.LearnedScorer.
                                from_model_checkpoint(
                                    cfg.Config.from_file(model_config),
                                    config.get("checkpoint")))
                else:
                    raise ValueError(
                        "Invalid scorer type: {}".format(scorer_type))