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()));
}
}
}
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());
}
}
}
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);
}
}
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);
}
}
Aggregations