Search in sources :

Example 1 with RankingConstant

use of com.yahoo.searchdefinition.RankingConstant in project vespa by vespa-engine.

the class TensorFlowFeatureConverter method transformLargeConstant.

private void transformLargeConstant(ModelStore store, RankProfile profile, QueryProfileRegistry queryProfiles, Set<String> constantsReplacedByMacros, String constantName, Tensor constantValue) {
    RankProfile.Macro macroOverridingConstant = profile.getMacros().get(constantName);
    if (macroOverridingConstant != null) {
        TensorType macroType = macroOverridingConstant.getRankingExpression().type(profile.typeContext(queryProfiles));
        if (!macroType.equals(constantValue.type()))
            throw new IllegalArgumentException("Macro '" + constantName + "' replaces the constant with this name. " + "The required type of this is " + constantValue.type() + ", but the macro returns " + macroType);
        // will replace constant(constantName) by constantName later
        constantsReplacedByMacros.add(constantName);
    } else {
        Path constantPath = store.writeLargeConstant(constantName, constantValue);
        if (!profile.getSearch().getRankingConstants().containsKey(constantName)) {
            profile.getSearch().addRankingConstant(new RankingConstant(constantName, constantValue.type(), constantPath.toString()));
        }
    }
}
Also used : Path(com.yahoo.path.Path) RankProfile(com.yahoo.searchdefinition.RankProfile) TensorType(com.yahoo.tensor.TensorType) RankingConstant(com.yahoo.searchdefinition.RankingConstant)

Example 2 with RankingConstant

use of com.yahoo.searchdefinition.RankingConstant in project vespa by vespa-engine.

the class AbstractSearchCluster method prepareToDistributeFiles.

public void prepareToDistributeFiles(List<SearchNode> backends) {
    for (SearchDefinitionSpec sds : localSDS) {
        for (RankingConstant constant : sds.getSearchDefinition().getSearch().getRankingConstants().values()) {
            FileReference reference = (constant.getPathType() == RankingConstant.PathType.FILE) ? FileSender.sendFileToServices(constant.getFileName(), backends) : FileSender.sendUriToServices(constant.getUri(), backends);
            constant.setFileReference(reference.value());
        }
    }
}
Also used : FileReference(com.yahoo.config.FileReference) RankingConstant(com.yahoo.searchdefinition.RankingConstant)

Example 3 with RankingConstant

use of com.yahoo.searchdefinition.RankingConstant in project vespa by vespa-engine.

the class RankingConstantsValidator method validate.

@Override
public void validate(VespaModel model, DeployState deployState) {
    ApplicationPackage applicationPackage = deployState.getApplicationPackage();
    ExceptionMessageCollector exceptionMessageCollector = new ExceptionMessageCollector("Invalid constant tensor file(s):");
    for (SearchDefinition sd : deployState.getSearchDefinitions()) {
        for (RankingConstant rc : sd.getSearch().getRankingConstants().values()) {
            try {
                validateRankingConstant(rc, applicationPackage);
            } catch (InvalidConstantTensor | FileNotFoundException ex) {
                exceptionMessageCollector.add(ex, rc.getName(), rc.getFileName());
            }
        }
    }
    if (exceptionMessageCollector.exceptionsOccurred) {
        throw new TensorValidationFailed(exceptionMessageCollector.combinedMessage);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) ApplicationPackage(com.yahoo.config.application.api.ApplicationPackage) FilesApplicationPackage(com.yahoo.config.model.application.provider.FilesApplicationPackage) SearchDefinition(com.yahoo.vespa.model.search.SearchDefinition) RankingConstant(com.yahoo.searchdefinition.RankingConstant) InvalidConstantTensor(com.yahoo.vespa.model.application.validation.ConstantTensorJsonValidator.InvalidConstantTensor)

Example 4 with RankingConstant

use of com.yahoo.searchdefinition.RankingConstant in project vespa by vespa-engine.

the class RankingExpressionWithTensorFlowTestCase method assertLargeConstant.

/**
 * Verifies that the constant with the given name exists, and - only if an expected size is given -
 * that the content of the constant is available and has the expected size.
 */
private void assertLargeConstant(String name, RankProfileSearchFixture search, Optional<Long> expectedSize) {
    try {
        Path constantApplicationPackagePath = Path.fromString("models.generated/mnist_softmax/saved/constants").append(name + ".tbf");
        RankingConstant rankingConstant = search.search().getRankingConstants().get(name);
        assertEquals(name, rankingConstant.getName());
        assertTrue(rankingConstant.getFileName().endsWith(constantApplicationPackagePath.toString()));
        if (expectedSize.isPresent()) {
            Path constantPath = applicationDir.append(constantApplicationPackagePath);
            assertTrue("Constant file '" + constantPath + "' has been written", constantPath.toFile().exists());
            Tensor deserializedConstant = TypedBinaryFormat.decode(Optional.empty(), GrowableByteBuffer.wrap(IOUtils.readFileBytes(constantPath.toFile())));
            assertEquals(expectedSize.get().longValue(), deserializedConstant.size());
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : Path(com.yahoo.path.Path) Tensor(com.yahoo.tensor.Tensor) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) RankingConstant(com.yahoo.searchdefinition.RankingConstant)

Aggregations

RankingConstant (com.yahoo.searchdefinition.RankingConstant)4 Path (com.yahoo.path.Path)2 FileReference (com.yahoo.config.FileReference)1 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)1 FilesApplicationPackage (com.yahoo.config.model.application.provider.FilesApplicationPackage)1 RankProfile (com.yahoo.searchdefinition.RankProfile)1 Tensor (com.yahoo.tensor.Tensor)1 TensorType (com.yahoo.tensor.TensorType)1 InvalidConstantTensor (com.yahoo.vespa.model.application.validation.ConstantTensorJsonValidator.InvalidConstantTensor)1 SearchDefinition (com.yahoo.vespa.model.search.SearchDefinition)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1